验证组件通信问题(属性/事件-父子通信)
您好,我尝试在父级和子级之间传递数据,如下教程所示:https://www.youtube.com/watch?v=PPmg7ntQjzc
常规的HTML输入可以很好地工作(就像在教程中一样)。
但验证文本字段或文本区域不起作用。(乍一看似乎还不错。当我开始输入时,它给出错误)
我做错了什么?
//子HTML
<input
type="text"
placeholder="regular child"
:value="valueRegularChild"
@input="inputRegularChild"
>
<p>{{ regularInputValue }}</p>
<v-textarea
type="text"
placeholder="vuetify child"
:value="valueVuetifyChild"
@input="inputVuetifyChild"
></v-textarea>
<p>{{ vuetifyInputValue }}</p>//子方法
inputVuetifyChild($event) {
this.vuetifyInputValue = $event.target.value;
this.$emit('msgVuetify', this.vuetifyInputValue);
},
inputRegularChild($event) {
this.regularInputValue = $event.target.value;
this.$emit('msgRegular', this.regularInputValue);
},//父HTML
<child-component
:valueVuetifyChild="insideParentVuetify"
:valueRegularChild="insideParentRegular"
@msgVuetify="insideParentVuetify = $event"
@msgRegular="insideParentRegular = $event"
>
<child-component>一切都一样。
常规工作,请勿进行验证
consol日志错误显示:
TypeError:无法读取未定义的属性“value”
提前感谢
发布于 2019-04-10 17:12:13
我认为v-model应该比:value工作得更好,但是还没有时间测试它。
//子HTML
<input
type="text"
placeholder="regular child"
v-model="valueRegularChild"
@input="inputRegularChild"
>
<p>{{ regularInputValue }}</p>
<v-textarea
type="text"
placeholder="vuetify child"
v-model="valueVuetifyChild"
@input="inputVuetifyChild"
></v-textarea>
<p>{{ vuetifyInputValue }}</p>//子方法
inputVuetifyChild($event) {
this.$emit('msgVuetify', this.vuetifyInputValue);
},
inputRegularChild($event) {
this.$emit('msgRegular', this.regularInputValue);
},//父HTML
<child-component
:valueVuetifyChild="insideParentVuetify"
:valueRegularChild="insideParentRegular"
@msgVuetify="insideParentVuetify = $event"
@msgRegular="insideParentRegular = $event"
>
<child-component>https://stackoverflow.com/questions/55608005
复制相似问题