使用 Element UI Table 的 slot-scope方法
阿新 • • 發佈:2020-11-18
在 Element UI Table 的官網上,有一個“篩選”功能,裡面可以利用 slot-scope,給表格記錄打標籤。
關鍵程式碼為:
<template slot-scope="scope"> <el-tag :type="scope.row.tag === '家' ? 'primary' : 'success'" disable-transitions>{{scope.row.tag}}</el-tag> </template>
- 這裡首先利用 slot-scope 屬性(Vue 2.6.0 已廢棄)將子元件的資料(row.tag)傳遞給了父元件。
- 利用三元表示式為 <el-tag> 標籤設定樣式。
實踐過程中,發現這個三元表示式沒法應用。因為實際業務場景,記錄型別肯定不止兩個啊!
這時,就該條件渲染指令出場了:
<el-tag v-if="scope.row.state === '已完成'" :type="'success'" disable-transitions>{{scope.row.state}} </el-tag> <el-tag v-else-if="scope.row.state === '未開始'" :type="'danger'" disable-transitions>{{scope.row.state}} </el-tag> <el-tag v-else-if="scope.row.state === '進行中'" :type="'warning'" disable-transitions>{{scope.row.state}} </el-tag>
執行結果:
官網只是基本用法,真正實踐還是要靠積累與總結哦O(∩_∩)O哈哈~
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援碼農教程。