在created 中,如果第一次载入app,就用weex的storage 获取city 这个key,如果没有就跳转到city页面去,现在的情况是 2 可以打印出来,第一次确实storage里面确实没值。 为什么_this.$router.push('/home/city') 没有生效
created() {
var _this = this;
storage.getItem('city',e => {
if(e.result != "failed" ){
_this.$store.commit('CURRENTCITY',e.data);
console.log(1);
}else {
console.log(2);
_this.$router.push('/home/city');
}
})
},
并且将它不放在storage 中,直接放到created中也不生效
created() {
this.$router.push('/home/city');
},
但是如果做个点击事件,在事件中又是生效的
试试放在
mounted
中呢,可能是界面没有渲染完成你就去push了呢