bootstrap-table formatter 使用vue组件

import { Subject } from "rxjs";
import Vue from "vue";

export const BtEventHub = new Subject();

const VueComList = [];
let VueComId = 0;

BtEventHub.debounceTime(10)
  .filter(() => VueComList.length > 0)
  .delay(10)
  .subscribe(function() {
    const len = VueComList.length - 1;

    for (let i = len; i >= 0; i--) {
      const item = VueComList[i];
      const dom = document.getElementById(item.name);

      if (dom != null) {
        new Vue(item);
        VueComList.splice(i, 1);
      }
    }

    if (VueComList.length === 0) {
      VueComId = 0;
    }
  });

export function BtAddVueCom(obj: object) {
  const id = `_vue_com_${VueComId++}`;

  VueComList.push({
    el: "#" + id,
    name: id,
    ...obj
  });

  setTimeout(() => {
    BtEventHub.next();
  }, 0);

  return id;
}

window["BtAddVueCom"] = BtAddVueCom;
function ColFormatter1(value, row) {
  const id = window.BtAddVueCom({
    template: '<el-switch v-model="row.IsShow"></el-switch>',
    data: function () {
      return {
        row
      }
    }
  });
  return `<div id="${id}"></div>`;
}
    原文作者:Chobits
    原文地址: https://segmentfault.com/a/1190000019115038
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞