每日一句: Knowledge is a treasure, but practice the key to it. 知识是一座宝库,实践是打开宝库的钥匙。

uni-app中Vuex的引用

 

 

//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
    }
}




 */

 

posted @ 2019-01-28 16:03  wuyongmao  阅读(5346)  评论(0编辑  收藏  举报