vue3.2(setup语法糖)父子组件间传值
一、父给子发信息父组件发送信息给子组件index.vueimport Back from '@/components/common/back.vue'const title = ref('你好呀')// template部分<Back :title="title" />子组件接收父组件信息/components/common/back.vue<script setup>im
·
一、父给子发信息
对您有用的话记得点个赞哦 ~
父组件发送信息给子组件
index.vue
import Back from '@/components/common/back.vue'
const title = ref('你好呀')
// template部分
<Back :title="title" />
子组件接收父组件信息
/components/common/back.vue
<script setup>
import { toRefs } from 'vue'
const props = defineProps({
title: {
type: String,
default: '标题',
required: true,
},
})
const { title } = toRefs(props)
</script>
<template>
<span>{{ title }}</span>
</template>
二、子给父发信息
子组件发信息给父组件
/components/relax/relax-index.vue
const emit = defineEmits(['goTreeHode'])
const goHold = () => {
emit('goTreeHode', true)
}
//template
<button @click="goHold">传值</button>
父组件接收子组件信息
relax.vue
import RelaxIndex from '@/components/relax/relax-index.vue'
//template
<RelaxIndex @goTreeHode="goTreeHode" />
更多推荐
已为社区贡献11条内容
所有评论(0)