vue-cli-webpack 工程:
Myhome.vue 文件如下:
<template> <did> <Person v-model="homeaddress">a</Person> <p>{{homeaddress}}</p> </did> </template> <script> import Person from ‘./Person‘ export default { data: function () { return { homeaddress: ‘新县‘ } }, components: { Person } } </script>
Person.vue 文件
<template> <div> <label for="001"></label> <input id="001" type="text" v-model="address" @input="onpersoninput" /> </div> </template> <script> export default { model: { prop: ‘address‘, event: ‘chgaddress‘ }, props: [‘address‘], methods: { onpersoninput (event) { this.$emit(‘chgaddress‘, this.address) } } } </script>
model 作用是声明 v-model 绑定的数据和事件
原文:https://www.cnblogs.com/wudeyun/p/15000276.html