在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/iOS  HTML/ vuex數(shù)據(jù)更新但是視圖不會更新

vuex數(shù)據(jù)更新但是視圖不會更新

1描述:vue2+vuex用的webpack打包

vuex通過mutations方式更改數(shù)據(jù),數(shù)據(jù)確實(shí)更新了,但是頁面并沒有更新,通過排查發(fā)現(xiàn)是引用store方式的問題
以下是code:

//index.js
"use strict";
import Vue from 'Vue'; 
import Vuex from 'vuex';
import store from '../../vuex/store.js';
import VueRouter from 'vue-router';
import routers from '../../routers/routers';
Vue.use(Vuex);
Vue.use(VueRouter);

Vue.config.debug = true;//開啟錯誤提示

const router = new VueRouter({
    //mode: 'history',
    //scrollBehavior: () => ({ y: 0 }),
    routes: routers
})


//vuex
//const store = new Vuex.Store({
//    state: {
//        count: 0
//    },
//    mutations: {
//        increment: state => state.count++,
//        decrement: state => state.count--
//    }
//})

const app = new Vue({
    router,
    store,
    computed: {
        indexData () {
            return this.$store.state.count
        }
    },
    methods: {
        increment () {
            this.$store.commit('increment')
        },
        decrement () {
            this.$store.commit('decrement')
        }
    },
    mounted: function () {
    },
}).$mount('#app')
//index.html
 <div id="app">
        <h1>Hello App!</h1>
        <p>
            <div>vuex data: {{ indexData }}</div>
            <div><a href="javascript:;" @click="increment">IncrementCount</a></div>
            <div><a href="javascript:;" @click="decrement">DecrementCount</a></div>
        </p>
    </div>
//store.js
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);

const state ={
    count: 0
}
const mutations ={
    increment: state => state.count++,
    decrement: state => state.count--
}

export default new Vuex.Store({
    state,
    mutations
})

以上是主要的代碼
在index.js中使用import的方式引入store就會出現(xiàn)描述的問題
如果直接在index.js中直接定義store(注釋部分)就不會出現(xiàn)上述問題

回答
編輯回答
汐顏

store里面vue小寫了。。。蠢比問題

2017年9月21日 18:09
編輯回答
命多硬

我靠,我也是這個問題,V大寫了

2018年7月20日 16:09