Vue3 parent-child component pass value

1. Pass value from parent component to child component

1), in the parent component

 2) Use props to accept values ​​in subcomponents

        

The method uses the value passed from the parent component

        

props.sonValue

 2. The child component passes the value to the parent component

1), in the subcomponent

const emit = defineEmits(['searchData'])
const submit = () => {
    emit('searchData', [vtType.value, vtLevel.value])  // 子组件将值传递给父组件
    props.sonUse()   // 子组件中使用父组件的方法
}

2), the parent component receives the value

// template 中

<RegionalSelect  @search-data="searchData" />   // 子组件



// methond 中
const searchData = (val) => {
  console.log(val)   // 获取到的子组件的值
}

Guess you like

Origin blog.csdn.net/2301_76882889/article/details/131060200