【发布时间】:2018-12-08 10:10:06
【问题描述】:
我有一个简单的组件,我尝试以两种方式绑定道具,但它只能以一种方式工作。当我更改输入字段中的文本时,它显示“初始属性 1”是 myprop1 的值,尽管我更改了输入。有什么问题?
我的组件
Vue.component('simple-input', {
template: `
<div>
<input type="text" :myprop1="myprop1" :value="myprop1" @input="$emit('input', $event.target.value)">
<input type="text" :myprop2="myprop2" :value="myprop2" @input="$emit('input', $event.target.value)">
</div>
`,
props: ['myprop1', 'myprop2']
});
main.js
new Vue({
el: '#root',
data: {
myprop1: 'Initial property 1',
myprop2: 'Initial property 2',
},
methods: {
showMe()
{
alert('prop1 - ' + this.myprop1);
alert('prop2 - ' + this.myprop2);
this.myprop1 = 'new value';
this.myprop2 = 'new value';
}
}
});
HTML
<simple-input :myprop1="myprop1" :myprop2="myprop2"></simple-input>
<button @click="showMe">Show me!</button>
【问题讨论】:
-
因为我不知道如果我有 2 个道具 - 每个输入一个道具
标签: javascript vue.js