用this.$store.state.online来记录登录状态,然后导航栏根据this.online来显示不同的选项。this.$store.state.online会在渲染完导航栏后发送ajax改变,也会在登录后改变。
但是无论是用mounted还是compute,当this.$store.state.online改变时,都不会改变this.online
所以造成的现象就是,登陆完,只有刷新页面,才会更新this.online
登录时:
this.$http.post('/api/login', data)
.then(res => { // success
if(res.body.user) {
this.$store.state.online = true;
this.$router.push('/');
}
});
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
$store.state中的值只能通过mutations或actions来改变的,不能直接赋值。
https://vuex.vuejs.org/zh-cn/...