首页 > 技术文章 > uni-app中Vuex的引用

J-wym 2019-01-28 16:03 原文

 

 

//store 中  store.js   
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: { 
        author: 'Youngmon' 
    },
    mutations: {
        author(state, newName) {
            state.author = newName;
        } 
    },
    actions: { }
})

export default store

/**
//main.js    新增
import store from './store' 
Vue.prototype.$store = store




//demo.vue
 this.$store.commit("author","yongmao");


computed: {
    author() {
        return this.$store.state.author
    }
}




 */

 

推荐阅读