【发布时间】:2018-08-06 21:33:23
【问题描述】:
我想从子组件中更改父级道具的值。这在 vuejs 1 中效果很好,但在 vue 2 中效果不佳(我想在 vue.js 2 中使用它)。
这是一个小例子:
HTML
<div id="app">
<parent :content="{value:'hello parent'}"><</parent>
</div>
JavaScript
var parent = {
template: '<child :content="content"></child>',
props: ['content'],
};
var child = {
template: '<div>{{ content.value }}<button @click="change">change me</button></div>',
props: ['content'],
methods: {
change() {
this.content.value = "Value changed !";
}
}
};
Vue.component('child', child);
Vue.component('parent', parent);
new Vue({
el: '#app',
});
【问题讨论】:
标签: javascript vue.js vuejs2