子組件 MyBar
<template>
<div>
<slot name="two" :user1='usname'></slot>// 有名字的插槽
<slot :user='usname'></slot> //無名字插槽 :user 自己命名的屬性,'usname'就是data里的值
//通過屬性把數據放到插槽里面
</div>
</template>
js部分
data(){
return{
usname:{name:'eduwork}
}
}
父組件 MySideBar
<template>
<div>
<my-bar> //子組件
<template v-slot:two='hello'> //獲取插槽名為two來獲取user1儲存的那個數據
<a href="">{{hello.user1.name}}</a>
</template>
//v-slot:插槽名='順便起個名字'
<template v-slot:default='word'> //當插槽無名字時可使用default,隨便命名一個名字,通過這個名字來獲取slot的屬性名來獲取數據
<a href="">{{word.user.name}}</a>
</template>
</my-bar>
</div> </template>
