父?jìng)髯?/p>
父組件
<template>
? ?<sonComponent?:sendValue="value(//傳遞的值)"></sonComponent>
</template>
//引入組件
import sonComponent from "XXXXX";
子組件
//定義名字與父組件對(duì)應(yīng)const props = defineProps({
? sendValue:{type: String,default:''}?
})
子傳父
子組件
// 定義發(fā)送const emit = defineEmits(['sendValue'])
//發(fā)送(在想傳參的時(shí)候調(diào)用方法)
function psendValuet(){
? emit('sendValue',value(//傳遞的值))
}
父組件 (@xxxx需要和子組件對(duì)應(yīng))
<template>
? ?<sonComponent?@sendValue="getValue(//綁定方法)"></sonComponent>
</template>
// 獲取子組件值
function getValue(val){
? ?console.log(val)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-468303.html
},文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-468303.html
到了這里,關(guān)于VUE3父子組件傳參的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!