车钥匙
⼦组件将需要⼀个 title和name prop 并发出 update:title update:name 事件来进⾏同步//father.vue <template > <div > {{bookTitle }} <Child v -model :title ="bookTitle" v -model :name ="name"></Child > {{name }} </div ></template ><script setup >import Child from './child'import { ref } from 'vue'const bookTitle = ref ('hello vue3');const name = ref ('张三');console .log (name );</script >
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
a8制造17睿翼油耗
18
起亚kx519
20
//child.vue <template > <div > <input type ="text" :value ="title" @input ="emits('update:title', $event.target.value)" /> <button @click ="edit">修改</button > </div ></template ><script setup >import { defineProps , defineEmits } from "vue";const emits = defineEmits (["update:title","update:name"]); defineProps ({ name : { type : String }, title : String ,});const edit = () => { // 处理数据 // emits ("update:name","李四")}</script ><style ></style >1234567891011121314151617181920212223242526272829303132333435
>汽车招聘
发布评论