vuetemplate中slot-scope/scope怎么用

這篇文章主要為大家展示了“vue template中slot-scope/scope怎么用”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“vue template中slot-scope/scope怎么用”這篇文章吧。

按需網(wǎng)站設(shè)計(jì)可以根據(jù)自己的需求進(jìn)行定制,做網(wǎng)站、成都做網(wǎng)站構(gòu)思過(guò)程中功能建設(shè)理應(yīng)排到主要部位公司做網(wǎng)站、成都做網(wǎng)站的運(yùn)用實(shí)際效果公司網(wǎng)站制作網(wǎng)站建立與制做的實(shí)際意義

在vue 2.5.0+ 中slot-scope替代了 scope

template 的使用情形為,我們已經(jīng)封裝好一個(gè)組建,預(yù)留了插槽,使用 的插槽

首先 我們的創(chuàng)建一個(gè)組建

組建很簡(jiǎn)單有一個(gè) slot,slot有兩個(gè)屬性 a=123,b=msg

<template>
 <div>
  <div>下面是一個(gè)slot</div>
  <slot a="123" b="msg" ></slot>
 </div>
</template>

接下來(lái)我們引入組建,并使用組建,引入的組建名 為mysolt,并使用組建

然后使用 template ,并使用scope/slot-scope,

<div>
 <mysolt>
   <template scope="msg">
    <div>下面是solt的props 調(diào)用</div>
    <div>{{msg}}</div>
    <div>{{msg.a}}</div>
    <div>{{msg.b}}</div>
   </template>
 </mysolt>
</div>

渲染圖如下:

vue template中slot-scope/scope怎么用

其實(shí)就是 template 通過(guò)scope/slot-scope 屬性 調(diào)用組建 slot 的屬性,以達(dá)到可以調(diào)用組建屬性實(shí)現(xiàn)復(fù)雜的嵌套;

實(shí)例中 我使用 msg 來(lái)重命名 slot 的屬性對(duì)象,即 msg 為slot 的{a:'123',b:'msg'}, 就可以通過(guò)使用msg 在template 中使用slot的屬性

(注意:當(dāng)前層 如果有data已經(jīng)聲明過(guò) msg,它們之間互不干擾,template 的msg 以slot 的為準(zhǔn))

如果我給當(dāng)前 data的msg={c:111},效果圖如下:

<div>{{msg.c}}</div>

 <mysolt>
  <template scope="msg">
   <div>下面是solt的msg</div>
   <div>{{msg}}</div>
   <div>{{msg.a}}</div>
   <div>{{msg.b}}</div>
   <div>{{msg.c}}</div>
  </template>
 </mysolt>

vue template中slot-scope/scope怎么用

以上是“vue template中slot-scope/scope怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)頁(yè)題目:vuetemplate中slot-scope/scope怎么用
文章來(lái)源:http://muchs.cn/article46/ijdieg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、面包屑導(dǎo)航App開(kāi)發(fā)、小程序開(kāi)發(fā)網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)