我正在尝试使用NuxtJS构建一个编辑用户页面。我希望在表单字段中预先填充来自API调用的用户当前信息。问题是该信息仅在我刷新页面(CMD + R)时出现,而当我从其他位置导航至编辑用户页面时(例如如果我在个人资料页面上,然后单击“编辑个人资料”按钮,则表单字段均为空白。这是我的代码中的相关部分:
<template>
<b-field label="Profile Description">
<b-input v-model="description"></b-input>
</b-field>
</template
export default {
data() {
return {
description: "",
};
},
mounted() {
this.$store
.dispatch("getUser")
.then(response => {
this.description = response.description;
})
.catch(e => {
console.log(e);
});
}
}
什么是允许在页面刷新和导航到页面上预先填充表格的最佳方法?我尝试过使用created()生命周期和强制刷新组件而没有成功。