Vue CLI / Nuxt.js の場合
子コンポーネントのmodel
で親コンポーネントのv-model
に使用するプロパティとイベントを用意し、this.$emit
で親要素に返す。
例のコードでは、changeValue
関数をinput
タグでv-bind:input
イベントで呼び出し、そのまま親要素に返すようにしている。
CDNの場合
test
Vue.component('sample-component', {
model: {
prop: 'name',
event: 'input-name',
},
methods: {
changeValue() {
this.$emit('input-name', this.name);
},
},
template:`
`,
})
コメント