效果如图所示:
代码如下:
1. html代码
<n-data-table
:columns="xxxColumns"
:data="xxxData"
striped
scroll-x
max-height="350"
style="margin-bottom: 14px"
:bordered="false"
:size="'small'"
/>
2. js代码
import {h, ref} from "vue";
// 引入表格组件和日期组件
import {NDataTable, NDatePicker} from "naive-ui";
// 表头
const xxxColumns = ref([
{
title: "序号",
fixed: "left",
key: "xh",
width: 80,
align: 'center',
render: (_, index) => {
return `${index + 1}`;
},
},
{
title: "测试",
key: "cs",
width: 280,
align: 'center',
ellipsis: {
tooltip: true,
},
// 重要代码
render(row,index) {
return h(NDatePicker, {
'formatted-value': row.cs,
'value-format':"yyyy-MM-dd",
onUpdateFormattedValue(v) {
xxxData.value[index].sx = v;
}
});
}
},
])
const xxxData = ref([
{cs:'2024-12-16'},
{cs:'2024-12-03'}
])