? 1、作用:讓父組件可以向子組件指定位置插入html結(jié)構(gòu),也是一種組件之間通信的方式,
???????????????????? 適用于 父組件===>子組件。
? 2、分類:默認(rèn)插槽、具名插槽、作用域插槽
? 3、使用方式:
? ? ? 1、默認(rèn)插槽:?
? ? ? ? 父組件中:
? ? ? ? ? ? <Category>
? ? ? ? ? ? ? <div>html結(jié)構(gòu)</div>
? ? ? ? ? ? </Category>
? ? ? ? 子組件中:
? ? ? ? ? ? <template>
? ? ? ? ? ? ? <div>
? ? ? ? ? ? ? ? ? //定義一個(gè)插槽
? ? ? ? ? ? ? ? ? <slot>插槽默認(rèn)內(nèi)容</slot>
? ? ? ? ? ? ? </div>
? ? ? ? ? ? </template>
? ? ? 2、具名插槽:
? ? ? ? 父組件中:
? ? ? ? ? <Category>
? ? ? ? ? ? <template slot="center">?????? //當(dāng)多個(gè)插槽時(shí) 選擇該結(jié)構(gòu)放入哪一個(gè)插槽
? ? ? ? ? ? ? ?? <div>html結(jié)構(gòu)1</div>
? ? ? ? ? ? </template>
? ? ? ? ? ? <template v-slot:footer>??? //當(dāng)用到template時(shí) 在vue2.6中有新寫法
? ? ? ? ? ? ??????? <div>html結(jié)構(gòu)2</div>
? ? ? ? ? ? </template>
//如果沒有template。直接在結(jié)構(gòu)上寫slot=“center”
? ? ? ? ? </Category>
? ? ? ? 子組件中:
? ? ? ? ? ? <template>
? ? ? ? ? ? ? <div>
? ? ? ? ? ? ? ? //定義插槽
? ? ? ? ? ? ? ? <slot name="center"></slot>
? ? ? ? ? ? ? ? <slot name="footer"></slot>
? ? ? ? ? ? ? </div>
? ? ? ? ? ? </template>
? ? ? 3、作用域插槽
? ? ? ? 1、理解:數(shù)據(jù)在組件的自身,但根據(jù)數(shù)據(jù)生成的結(jié)構(gòu)需要組件的使用者來決定。(games數(shù)據(jù)在Category中,但使用數(shù)據(jù)所遍歷出來的結(jié)構(gòu)由
? ? ? ? App組件來決定)
? ? ? ? 2、具體編碼:
<slot :games="games"></slot>??? //把數(shù)據(jù)傳給插槽

//想要拿到插槽傳入的games數(shù)據(jù)?? 必須用template標(biāo)簽
? 接受數(shù)據(jù) scope=“{games}”?
?????? 新寫法:slot-scope = “{games}”
