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

v-slot和slot、slot-scope之間相互替換實例

 更新時間:2020年09月04日 11:27:23   作者:摸咸魚  
這篇文章主要介紹了v-slot和slot、slot-scope之間相互替換實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

如果組件文檔里面用的是v-slot,而你用的是vue2.6之前的版本,則需要替換v-slot:所以有兩種替換方式,注意看兩塊v-slot有啥不同,你就知道你該怎么用slot-scope和slot來替換文檔中的v-slot了

v-slot使用方式1:

<template v-slot:operate="{ row }"><template>

則可替換為:

<template slot="operate" slot-scope="{ row }"></template>

v-slot使用方式2:

<template v-slot="{ row }"><template>

則可替換為:

<template slot-scope="row"></template>

先記錄后期再完善,趕項目去了

補充知識:V-for and slot-scoped報錯問題

此場景是為了用v-for動態(tài)渲染表格的slot

可能會這么寫

<a-table>
 <span v-for="(item, index) in header" :key="index" :slot="item.dataIndex" slot-scope="text" >
  {{ text }}
 </span>
</a-table>

但是這樣子會報錯,因為v-for和slot-scope在同一級

Ambiguous combined usage of slot-scope and v-for on (v-for takes higher priority). Use a wrapper < template> for the scoped slot to make it clearer.

提示在外邊包一層< template>,于是你可能改成下面這樣,但是也會報錯

<a-table>
 <template v-for="(item, index) in header" :key="index">
 <span :slot="item.dataIndex" slot-scope="text" >
  {{ text }}
 </span>
 </template>
</a-table>
< template> cannot be keyed. Place the key on real elements instead.

提示< template>template不能寫key, 即使沒有這個錯,表格數(shù)據(jù)也不會渲染出來,因為這一層沒有slot,應該說slot應該是放最外面,同時把:key放里面

改成如下

<a-table>
 <template v-for="(item, index) in header" :slot="item.dataIndex" slot-scope="text">
 <span :key="index">
  {{ text }}
 </span>
 </template>
</a-table>

以上解決問題

有個slot沒有渲染的問題

 <template v-for="(slotname, idx) in ['status', 'sub_account_status']" :slot="slotname" slot-scope="text" >
  <span :key="idx">
  <a-tag v-if="text === '正常'" color="blue">{{ text }}</a-tag>
  <a-tag v-else color="red">{{ text }}</a-tag>
  </span>
 </template>
 <!-- 包名稱、關(guān)聯(lián)賬號 -->
 <template v-for="(slotname, idx) in ['app_name', 'roles']" :slot="slotname" slot-scope="text" >
  <span :key="idx">
  <a-tooltip placement="top" >
  <template slot="title">
  <span v-for="(item, index) in text" :key="index">{{ item }}<br/></span>
  </template>
  <div class="tableHidden">
  <a-tag v-for="(item, index) in text" :key="index">{{ item }} </a-tag>
  </div>
  </a-tooltip>
  </span>
 </template>

好像是因為2個v-for="(slotname, idx)"里的slotname名字一樣了,對的,就是取的臨時變量名,修改成不一樣的就好了,神奇

 <template v-for="(name, idx) in ['status', 'sub_account_status']" :slot="name" slot-scope="text" >
  // 上面那個name
  <span :key="idx">
  。。。
  </span>
 </template>
 <!-- 包名稱、關(guān)聯(lián)賬號 -->
 <template v-for="(slotname, idx) in ['app_name', 'roles']" :slot="slotname" slot-scope="text" >
  <span :key="idx">
  。。。
  </a-tooltip>
  </span>
 </template>

以上這篇v-slot和slot、slot-scope之間相互替換實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue iview實現(xiàn)分頁功能

    vue iview實現(xiàn)分頁功能

    這篇文章主要為大家詳細介紹了vue iview實現(xiàn)分頁功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • vant組件中 dialog的確認按鈕的回調(diào)事件操作

    vant組件中 dialog的確認按鈕的回調(diào)事件操作

    這篇文章主要介紹了vant組件中 dialog的確認按鈕的回調(diào)事件操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • vue開發(fā)移動端使用better-scroll時click事件失效的解決方案

    vue開發(fā)移動端使用better-scroll時click事件失效的解決方案

    這篇文章主要介紹了vue開發(fā)移動端使用better-scroll時click事件失效的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • 詳解Electron中如何使用SQLite存儲筆記

    詳解Electron中如何使用SQLite存儲筆記

    這篇文章主要為大家介紹了Electron中如何使用SQLite存儲筆記示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • vue中radio單選框如何實現(xiàn)取消選中狀態(tài)問題

    vue中radio單選框如何實現(xiàn)取消選中狀態(tài)問題

    這篇文章主要介紹了vue中radio單選框如何實現(xiàn)取消選中狀態(tài)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • 詳解vue后臺系統(tǒng)登錄態(tài)管理

    詳解vue后臺系統(tǒng)登錄態(tài)管理

    這篇文章主要介紹了vue后臺系統(tǒng)登錄管理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-04-04
  • VUE中的mapState和mapActions的使用詳解

    VUE中的mapState和mapActions的使用詳解

    在VUE項目中經(jīng)常會用到mapState和mapActions,mapState主要用于同步全局的變量或者對象,這篇文章主要介紹了VUE中的mapState和mapActions的使用,需要的朋友可以參考下
    2022-06-06
  • Vue中使用flv.js播放視頻的示例詳解

    Vue中使用flv.js播放視頻的示例詳解

    這篇文章主要為大家詳細介紹了如何在Vue項目中使用flv.js播放視頻,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2024-04-04
  • vue實現(xiàn)動態(tài)表格提交參數(shù)動態(tài)生成控件的操作

    vue實現(xiàn)動態(tài)表格提交參數(shù)動態(tài)生成控件的操作

    這篇文章主要介紹了vue實現(xiàn)動態(tài)表格提交參數(shù)動態(tài)生成控件的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • vue2和vue3組件v-model區(qū)別詳析

    vue2和vue3組件v-model區(qū)別詳析

    v-model通常用于input的雙向數(shù)據(jù)綁定,它并不會向子組件傳遞數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于vue2和vue3組件v-model區(qū)別的相關(guān)資料,需要的朋友可以參考下
    2023-06-06

最新評論