核心代码:
第一种方式:render 属性设置
{
title: '测试',
key: 'TEST',
height: '100%',
isShow: 'true',
isNull: 'true',
render : (h, params) => {
return h('Form', [
h('Input', {
props: {
type: 'text',
value: params.row["绑定data中的key"] //使用data中的key
},
on: {
input: event => {
this.dataAttributeData[params.index]["绑定data中的key"] = event;//双向绑定
}
}
})
]);
};
}
columns代表表格的表头,将上方的对象加入到表格属性columns中,即可生成一个输入框,并且支持与表格数据中的字段进行双向绑定。
第二种方式:slot绑定
核心代码:
<Table
:columns="columns"
:data="dataAttributeData"
:height="tableHeight"
:width="tableWidth"
style="position: relative;height: 80%;width:100%"
highlight-row
size="small"
>
<template
slot-scope="{ row }"
slot="需要绑定的字段"
>
<input v-model="row.需要绑定的字段"></input>
</template>
<template
slot="action"
slot-scope="{ row, index }"
>
<Button
size="small"
style="margin-right: 5px"
@click="remove(index)"
>
移除
</Button>
</template>
</Table>
核心在于templa,slot用来绑定需要变为输入框的字段,这样即可回显数据,缺点是没法双向绑定,且需要变成输入框的字段变多的话比较繁琐。
综上比较推荐方法一