defineExpose方法关于封装组件太多没办法修改子组件数值这件事(常用于回显)

330 阅读1分钟

如果在父组件中无法直接修改子组件的值,可以考虑使用defineExpose方法暴露来修改子组件需要进行修改。

子组件抛出

import { ref,defineExpose } from "vue";
// 表单
const from = ref({
    name:'',
    floors:null,
    area:null,
    propertyFeePrice:null 
})
// 暴露from
defineExpose({ 
  from:from
})

父组件接收

    // 接收子组件抛出的表单对象
    const from = ref(null)
    const editBuildingItem = (item) => {
      dialogVisible.value = true
    //  from.value.from = item
      console.log(from.value.from)
    }

image.png

记录提醒自己哈哈哈!!!!!!!!!!