我的组件中有一个 Prop,它是一个 User 对象,然后我有这个函数:
onChange: function(event){
this.$v.$touch();
if (!this.$v.$invalid) {
this.$axios.put('update',{
code:this.user.code,
col:event.target.name,
val:event.target.value
}).then(response => {
this.user[event.target.name]=event.target.value
});
}
}
我可以在 Vue 控制台调试器中看到正确的属性已更新,该属性在组件创建时就存在但我引用它的模板不会刷新:
<p>Hi {{user.nickname}}, you can edit your details here:</p>
这些都在同一个组件中,因此我不会导航到子组件或父组件。我确定 props 在我的代码中的其他地方已经反应了?
好吧,看来这是有意的行为。根据文档https://v2.vuejs.org/v2/guide/components-props.html https://v2.vuejs.org/v2/guide/components-props.html在我遇到的情况下,应该将其处理为:
-
prop用于传入一个初始值;之后子组件希望将其用作本地数据属性。在这种情况下,
最好定义一个使用 prop 作为其属性的本地数据属性
初始值:
props: ['initialCounter'],
data: function () {
return {
counter: this.initialCounter
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)