Page Component
Create Page Component
TIP
Context Menu - [Module Path]: Zova Create/Page
Enter the name of the page component according to the prompt, such as counter, and the VSCode extension will automatically create a route record and a file directory
Route
src/suite/a-demo/modules/demo-basic/src/routes.ts
typescript
import Counter from './page/counter/index.vue';
export const routes: IModuleRoute[] = [
//
{ path: 'counter', component: Counter },
];- path:
counteris a relative path, and since the page component belongs to the moduledemo-basic, its absolute path is/demo/basic/counter
Directory
In Zova, a page component will be splited to four files:
src/suite/a-demo/modules/demo-basic/src/page/counter
src
└─ page
└─ counter
├─ index.vue
├─ controller.ts
├─ render.tsx
└─ style.ts| Name | Description |
|---|---|
| index.vue | define vue component |
| controller.ts | local bean for business logic |
| render.tsx | local bean for page render |
| style.ts | local bean for page style |
index.vue
vue
<script setup lang="ts">
import { useControllerPage } from 'zova';
import { ControllerPageCounter } from './controller.js';
import { RenderCounter } from './render.jsx';
import { StyleCounter } from './style.js';
useControllerPage(ControllerPageCounter, RenderCounter, StyleCounter);
</script>- Just import and use the
controllerbean,renderbean andstylebean inindex.vueas well useControllerPagewill automatically introduce an IOC container and inject the required bean instances into the container
controller.ts
typescript
@Local()
export class ControllerPageCounter {
count: number = 0;
increment() {
this.count++;
}
decrement() {
this.count--;
}
}- Define
controlleras a local bean using@Localto register it in the ioc container - Define a reactive state
countof typenumber - Directly modify the value of
countby vanilla javascript
render.tsx
typescript
@Local()
export class RenderCounter {
render() {
return (
<div>
<div>count(ref): {this.count}</div>
<button onClick={() => this.increment()}>Increment</button>
<button onClick={() => this.decrement()}>Decrement</button>
</div>
);
}
}- Define
renderas a local bean using@Localto register it in the ioc container - Write rendering logic using the
tsxsyntax in therendermethod - Directly obtain the value of
countby vanilla javascript
style.ts
typescript
@Local()
export class StyleCounter {}- Define
styleas a local bean using@Localto register it in the ioc container - Support powerful
css-in-jscapabilities, see: CSS-in-JS: Style & Theme
Page Parameters
You can pass the parameters to the page through the route. Zova enhances the page parameters and provides Typescript typing support