源代码如下
<template>
<div class="notice-table">
<a-table
:columns="columns"
:data-source="list"
size="middle"
:pagination="{
pageSize: 10
}"
:customRow="rowClick"
>
<template slot="OID" slot-scope="index">
<a>{{ index }}</a>
</template>
<!-- <router-link :to="{ name: 'notice-detail' }" slot="name" slot-scope="text">{{ text }}</router-link> -->
</a-table>
</div>
</template>
<script>
const columns = [
{
title: "序号",
dataIndex: "OID",
customRender: (text, row, index) => {
return <a href="javascript:;">{index}</a>;
}
},
{
title: "标题",
dataIndex: "TOPIC"
},
{
title: "发布日期",
dataIndex: "ISSUEDATE"
}
];
export default {
props: {
list: {
type: Array,
required: true
}
},
data() {
return {
columns
};
},
methods: {
rowClick() {
return {
on: {
click: () => {}
}
};
}
},
mounted() {
console.log(this.$props);
}
};
</script>
<style lang="less">
.notice-table .ant-pagination {
width: 100%;
margin: 16px auto;
text-align: center;
}
</style>
后来改为这样:
<template>
<div class="notice-table">
<a-table
:columns="columns"
:data-source="list"
size="middle"
:pagination="{
pageSize: 10
}"
:customRow="rowClick"
>
<template slot="OID" slot-scope="index">
<a>{{ index }}</a>
</template>
<!-- <router-link :to="{ name: 'notice-detail' }" slot="name" slot-scope="text">{{ text }}</router-link> -->
</a-table>
</div>
</template>
<script>
export default {
props: {
list: {
type: Array,
required: true
}
},
data() {
// 改动位置 columns
const columns = [
{
title: "序号",
dataIndex: "OID",
customRender: (text, row, index) => {
return <span>{index + 1}</span>
}
},
{
title: "标题",
dataIndex: "TOPIC"
},
{
title: "发布日期",
dataIndex: "ISSUEDATE"
}
];
return {
columns
};
},
methods: {
rowClick() {
return {
on: {
click: () => {}
}
};
}
}
};
</script>
<style lang="less">
.notice-table .ant-pagination {
width: 100%;
margin: 16px auto;
text-align: center;
}
</style>
原因分析是data初始化时并未将表格的表头部分渲染出来,导致vue的template渲染函数出错