时间:2021-10-15 08:21:39 | 栏目:vue | 点击:次
目标
<template> <my-form v-model="form"> </my-form> </template> <script> export default { data() { return { form: '' } } } <script>
实现
// my-form组件 <template> <form> <input v-model="model.val1" /> <textarea v-model="model.val2"></textarea> <form> </template> <script> export default { model: { prop: 'model', event: 'change' }, props: { model: Object } watch: { model(val){ this.$emit('change', val) } } } <script>
总结