$attrs
主要用于组件之间的隔代传值。例如有 父组件A,子组件B,孙组件C 三个组件。
在A组件中传值给C,可直接在B中的C上设置v-bind=“$attrs”,然后在C组件中用prop接收,此时就直接把值传给了C。
用法如下:
组件A(父)
<template>
<div class="home">
<span>A</span><br>
<About :numbers="numbers"></About>
</div>
</template>
组件B(子)
<template>
<div class="about">
<span>B</span><br>
<Index v-bind="$attrs"></Index>
</div>
</template>
组件C(孙)
<template>
<div class="index">
<span>C</span><br>
<span>A传过来的值是:{{this.numbers}}</span>
</div>
</template>
<script>
export default {
name: "Index",
props:{
numbers :'',
}
</script>