原因
我使用了iView的框架,想要把表格的配置提取出来,但是表格里面的操作需要用到this,所以就需要在js文件中引用vue实例。
方法
utils - local-data.js
// vue实例
let newVue = {
obj: null
}
// iView表格部分代码,将columns暴露出去,在需要的地方引入
{
title: '操作',
key: 'operatorCode',
align: 'center',
width: 200,
render: (h, params) => {
return h('div', [
h('Button', {
props: {
type: 'text',
size: 'small'
},
style: {
color: '#FC9153'
},
on: {
click: () => {
newVue.obj.getDetail(params.row.id)
}
}
}, '详情'),
// ...
]);
}
}
export { newVue }
使用表格的组件
import { newVue } from '@/utils/local-data'
created () {
newVue.obj = this
},