base-table 加入动态slot 流程 vue2

columns

{
    title: '字段标题',
    slot: 'yourSlotName',
    minWidth: 50,
    align: 'center'
  },

组件内

props: {
    columns: {
      type: Array,
      default () {
        return []
      }
    },
mounted () {
    this.getSlot()

data () {
    return {
      slotArr: [],

methods: {
    getSlot () {
      this.slotArr = []
      this.columns.forEach(item => {
        if (item.slot) {
          this.slotArr.push(item.slot)
        }
      })
    },

组件外部调用

<base-table>
<template slot-scope="{ row, index }"
                slot="yourSlotName">
        <Button type="text"
                v-if="row.yourSlotName"
                @click="showData(index)"
                size="small">{{ row.yourSlotName}}</Button>
      </template>
</base-table>
---------------------------------------------
生活的意义并不是与他人争高下,而在于享受努力实现目标的过程,结果是对自己行动的嘉奖。
↑面的话,越看越不痛快,应该这么说:

生活的意义就是你自己知道你要做什么,明确目标。没有目标,后面都是瞎扯!
原文地址:https://www.cnblogs.com/pengchenggang/p/15236972.html