鍍金池/ 問答/HTML5  HTML/ vuex的值修改問題

vuex的值修改問題

我的項(xiàng)目用了vuex和router,然后我的store是直接寫在main.js中的,如下

const store = new Vuex.Store({
  state: {
    urlex:'http://pj.dianmila.com/supersolid/images/',
    issign: 0,
    icon:'',
    name:''
  },
  mutations: {
    login(state,next){
    axios.post('url')
    .then(function (res) {
                var datajson = res.data;
                state.issign = datajson.state;
                state.icon=datajson.img;
                state.name=datajson.nickname;
                if(datajson.state == 1) {
                    axios.post('url')
                    .then(function (res) {
                                    var datajson = res.data
                                    var mylist = datajson.list[0]
                                    state.name=mylist.name
                                    next()
                            })
                    .catch(function (error) {
                    window.location.href = "url"
                    });
                }
                else next();
            })
    .catch(function (error) {
    window.location.href = "url"
    });
    }
  }
})

然后還定義了一個(gè)導(dǎo)航守衛(wèi)

router.beforeEach((to, from, next) => {
    window.document.title = '超固態(tài)社交站';
  store.commit('login',next)
})

然后發(fā)現(xiàn)運(yùn)行之后,那些store的state的值都沒改變,為什么呢,代碼也沒有報(bào)錯(cuò),就是store的值改變不了

問題描述

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

題目描述

題目來源及自己的思路

相關(guān)代碼

// 請(qǐng)把代碼文本粘貼到下方(請(qǐng)勿用圖片代替代碼)

你期待的結(jié)果是什么?實(shí)際看到的錯(cuò)誤信息又是什么?

回答
編輯回答
爆扎

打斷點(diǎn)看一下

2017年6月1日 01:36