父
<template>
<Child :user="users" @on-user-change="onUserChange" />
</template>
<script>
export default {
components: {
Child
},
data(){
return{
users:["admin"]
}
},
methods:{
onUserChange(val){
this.users = val;
}
}
}
</script>
子
<template>
<Input v-modal="_users" />
</template>
<script>
export default {
porps: {
users: {
type: Array,
default: () => {
return [];
},
},
},
computed: {
_users: {
get() {
return this.users;
},
set(val) {
// 只能由父组件改变其传入的值
this.$emit("on-user-change", val);
}
}
}
}
</script>