nuxt.js - 当页面刷新状态在nuxt js中为空时
问题描述
我是 Nuxt 的新手,我使用通用模式创建了一个项目,在页面刷新时维护用户状态时遇到问题,商店和身份验证模块在刷新时消失,因此无法在刷新时从商店中检索值。
解决方案
export const state = () => ({
data: []
})
//payload hold all form details,
//coming from home.vue
//use spread operator to access all form details
export const mutations = {
SET(state, data) {
state.data = data
}
}
export const actions = {
async addRootUser({commit}, user){
await this.$axios.$post( 'http://localhost:3001/owner',user ,{ header: {
'content-type': 'application/x-www-form-urlencoded'
} })
.then(response => {
console.log('hjfhjfh',response)
this.$router.push("/family");
//state.rootUsers = response
commit('SET', response)
if(process.browser){
localStorage.setItem("rootUser", response._id);
console.log('Set')
}
return response
}).catch((error) => {
console.log(error.response)
//this.errors = error.response.data.errors;
console.log('somthing went wrong.................')
})
}
}
[enter image description here][1]
[1]: https://i.stack.imgur.com/82q8b.png
推荐阅读
- c - 将打印队列的迭代函数转换为递归函数时出现问题
- construct - 构造 2 到构造 3 语法
- reactjs - Redux-saga root saga 中的多个 saga
- angular - Angular - 无法使用集合和 *ngFor 填充 mat-chip-list - 更新:设置 mat-select multiple 的值有问题吗?
- amazon-web-services - 从 Dialogflow 到 Alexa,如何创建 lambda 函数?
- python-3.x - fanyimpute 安装后,我在导入时遇到此错误
- docker - 在 docker 容器中使用 webhdfs 打开一个文件
- transfer-learning - 如何在 TF2.1 中保存/加载用于微调/迁移学习的部分模型?
- tfs - TFS 代码审查在更新代码审查状态时发生错误
- javascript - 无法将变量从 PHP 传递到 JavaScript