一个简单的 store 模式的应用
在src下新建 store/myStore.js
var myStore = {
debug: true,
state: {
msg: "hello"
},
setMsgAction(newValue) {
if (this.debug) console.log("setMsgAction trigged with ", newValue);
this.state.msg = newValue;
},
clearMsgAction() {
if (this.debug) console.log("clearMsgAction trigged");
this.state.msg = "";
}
};
export default myStore在需要使用 store 的 .vue 文件里面引入
import myStore from "@/store/myStore"; // 导入 myStore 文件在data里面设置
privateState: {},
sharedState: myStore.state
这样就和普通的data数据一样使用了
本文内容仅供个人学习/研究/参考使用,不构成任何决策建议或专业指导。分享/转载时请标明原文来源,同时请勿将内容用于商业售卖、虚假宣传等非学习用途哦~感谢您的理解与支持!