$attrs
主要用于組件之間的隔代傳值。例如有 父組件A,子組件B,孫組件C 三個(gè)組件。
在A組件中傳值給C,可直接在B中的C上設(shè)置v-bind="$attrs",然后在C組件中用prop接收,此時(shí)就直接把值傳給了C。
用法如下:
組件A
<template>
<bCom msg='123'/>
</template>
組件B
<template>
<cCom v-bind="$attrs"/>
</template>
組件C
<template>
<div>A傳遞過來的值:{{msg}}</div>
</template>
<script>
export default {
name: 'cCom',
props: {
msg:{ //接收A傳遞的msg
typeof:String,
default:''
}
},
}
</script>
組件隔代通訊其它相關(guān)用法:文章來源:http://www.zghlxwxcb.cn/news/detail-633960.html
Vue中v-on=“$listeners“的使用方法https://blog.csdn.net/weixin_44594219/article/details/127259825?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22127259825%22%2C%22source%22%3A%22weixin_44594219%22%7Dvue2中EventBus的使用方法https://blog.csdn.net/weixin_44594219/article/details/127248681?spm=1001.2014.3001.5502文章來源地址http://www.zghlxwxcb.cn/news/detail-633960.html
到了這里,關(guān)于Vue中v-bind=“$attrs”的使用方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!