【发布时间】:2019-11-09 17:17:31
【问题描述】:
我正在关注 vuex 表单处理的官方 vuex 教程:https://vuex.vuejs.org/guide/forms.html。我基本上复制粘贴了他们建议的 Two-way Computed Property 在底部的实现,但我仍然收到一个错误,说它无法读取未定义的属性“名称”:
[Vue warn]: Error in render: "TypeError: Cannot read property 'name' of undefined"
found in
---> <CustomForm> at src/components/Form.vue
<Register> at src/views/Register.vue
<App> at src/App.vue
<Root>
Form.vue:
<custom-input title="Name" v-model="name" placeholder="Name" required />
computed: {
name: {
get () {
return this.$store.state.form.name
},
set (value) {
this.$store.commit('updateForm', ('name', value))
}
}
我尝试在 get 函数中的 return 语句之前console.log(this.$store.state.form.name),但没有打印出来
【问题讨论】: