js 2.0,我有动态 Prop 。
见附件
我的 HTML 代码是这样的:
<div id="app">
<div>
<input v-model="parentMsg">
<br>
<child v-bind:my-message="parentMsg"></child>
</div>
</div>
我的组件代码:
Vue.component('child', {
props: ['myMessage'],
template: '<p>{{ myMessage }}</p>',
})
var app = new Vue({
el: "#app",
});
我知道数据应该是一个函数,但我将如何实现它。我在控制台上收到此错误。
Property or method "parentMsg" is not defined on the instance but referenced during render
最佳答案
我认为信息很明确。 “parentMsg”未在实例上定义
。您必须在父级定义 parentMsg
。像下面这样:
var app = new Vue({
data: {
"parentMsg": ""
}
el: "#app"
});
你可以有一个工作 fiddle here .
关于vuejs2 - Vue.js 2.0 动态 Prop 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42059338/