uni-app使用vuex

        
    //因为uniapp内部已经内置了vuex,只要正确引用就可以
    //1.根目录创建store文件->index.js import Vue from ‘vue’ import Vuex from ‘vuex’ Vue.use(Vuex) const store = new Vuex store ({ state: { name: ‘’ }, getters: { }, mutations: { }, actions: { } }) export default store //2.main.js下引入和挂载 import store from ‘./store’ Vue.prototype.$store = store const app = new Vue ({ store }) //3.页面引用 <template> <div> {{name}} </div> </template> <scipt> import {mapState} from ‘vuex’ export default { onLoad() { console.log(this.$store) }, computed: { …mapState([‘name’]) } } </script>

猜你喜欢

转载自www.cnblogs.com/wei-dong/p/12597244.html