一个简单的 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数据一样使用了
本文内容仅供个人学习、研究或参考使用,不构成任何形式的决策建议、专业指导或法律依据。未经授权,禁止任何单位或个人以商业售卖、虚假宣传、侵权传播等非学习研究目的使用本文内容。如需分享或转载,请保留原文来源信息,不得篡改、删减内容或侵犯相关权益。感谢您的理解与支持!