$listeners
用于底層組件向高級層組件傳遞信息。
例如有 父組件A,子組件B,孫組件C 三個組件,如果C傳遞信息給B則可直接使用$emit,如果是C向A傳遞信息還使用$emit,則就需要C先$emit給B,B再$emit給A,這種方式比較繁瑣,則此時(shí)可以使用v-on="$listeners"來滿足當(dāng)前需求。
用例:
C組件
<template>
<div @click="onClick">C組件</div>
</template>
onClick(){
this.$emit("Msg",'123')
}
B組件
<template>
<cCom v-on="$listeners"/>
</template>
A組件
<template>
<bCom @Msg='Msg'/>
</template>
methods:{
Msg(val){
console.log(val) //123
}
}
組件隔代通訊其它相關(guān)用法:文章來源:http://www.zghlxwxcb.cn/news/detail-621034.html
Vue中v-bind=“$attrs”的使用方法https://blog.csdn.net/weixin_44594219/article/details/127257804?spm=1001.2014.3001.5502vue2中EventBus的使用方法https://blog.csdn.net/weixin_44594219/article/details/127248681?spm=1001.2014.3001.5502文章來源地址http://www.zghlxwxcb.cn/news/detail-621034.html
到了這里,關(guān)于Vue中v-on=“$listeners“的使用方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!