父组件
1 <script lang="ts" setup> 2 import { ref } from 'vue' 3 const value = ref({ 4 page: 1, 5 size: 2, 6 selectId : "" 7 }) 8 </script> 9 10 <template> 11 <search-select v-model="value.selectId"></search-select> 12 </template>
子组件
1 <script setup> 2 defineProps(['modelValue','width']) 3 const emit = defineEmits(['update:modelValue']) 4 </script> 5 6 <template> 7 <el-select 8 9 :modelValue = modelValue 10 @update:modelValue="emit('update:modelValue',$event)" 11 placeholder="请选择" :style="{ width }"> 12 <el-option label="新闻" value="110">新闻</el-option> 13 <el-option label="科技" value="120">科技</el-option> 14 </el-select> 15 </template>
标签:vue,const,modelValue,update,父子相传,ref From: https://www.cnblogs.com/zhang-dan/p/18503046