我的项目用了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"
});
}
}
})
然后还定义了一个导航守卫
router.beforeEach((to, from, next) => {
window.document.title = '超固态社交站';
store.commit('login',next)
})
然后发现运行之后,那些store的state的值都没改变,为什么呢,代码也没有报错,就是store的值改变不了
问题描述
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
你期待的结果是什么?实际看到的错误信息又是什么?
题目描述
题目来源及自己的思路
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
打断点看一下