0.1.0 • Published 2 years ago
@noix/model-vue v0.1.0
@noix/model-vue
Adapter for @noix/model with vue3
Prerequisite
If you want use model, you need to wrap the component where you call related methods inside Container and use useModel/useDispatch to get the API.
//App.jsx
export const App = () => {
return (
<Container models={[demo]}>
<Counter />
</Container>
);
};
//Counter.jsx
export const Counter = () => {
const count = useModel("demo/count");
const addCount = useDispatch("demo/addCount");
return <button onClick={() => addCount()}>{count.value}</button>;
};
// demo.js
export const demo = {
name: "demo",
state: {
count: 0,
},
effect: {
addCount() {
this.setField("count", this.state.count + 1);
},
},
};
0.1.0
2 years ago