欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue template中slot-scope/scope的使用方法

 更新時間:2018年09月06日 10:26:49   作者:v折耳  
今天小編就為大家分享一篇vue template中slot-scope/scope的使用方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

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

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

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

組建很簡單有一個 slot,slot有兩個屬性 a=123,b=msg

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

接下來我們引入組建,并使用組建,引入的組建名 為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>

渲染圖如下:

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

實例中 我使用 msg 來重命名 slot 的屬性對象,即 msg 為slot 的{a:'123',b:'msg'}, 就可以通過使用msg 在template 中使用slot的屬性

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

如果我給當前 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的使用方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論