父传子:defineProps
在 <script setup>
块中是没有组件配置项的,也就是说是没有 props
选项,需要使用 defineProps
来声明 props
相关信息。defineProps
接收的对象和组件选项 props
的值一样。
父组件
子组件
子传父
父组件
子组件
非父子组件间传值
建立公共传值文件event-bus.ts:
内容如下
事件发出组件
事件监听组件
父传子:defineProps
在 <script setup>
块中是没有组件配置项的,也就是说是没有 props
选项,需要使用 defineProps
来声明 props
相关信息。defineProps
接收的对象和组件选项 props
的值一样。
父组件
子组件
子传父
父组件
子组件
非父子组件间传值
建立公共传值文件event-bus.ts:
内容如下
事件发出组件
事件监听组件