简单封装提起出列和数据
Compoents文件夹下加个 VTable.vue 文件,内容如下
<template>
<el-table :data="tableData" style=" 100%">
<el-table-column v-for="item in columns" :prop="item.prop" :label="item.label" :key="item.prop" ></el-table-column>
</el-table>
</template>
<script>
export default {
name:"VTable",
props:{
//接收列
columns:{
type:Array,
default:()=>[]
},
//接收数据
tableData:{
type:Array,
default:()=>[]
}
},
data() {
return {
}
}
}
</script>
<style>
</style>
在home.vue页面中使用
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<VTable :columns="columns" :tableData="tableData"></VTable>
</div>
</template>
<script>
// @ is an alias to /src
import VTable from '@/components/VTable.vue'
export default {
name: 'Home',
data(){
return{
//列数据
columns:[
{label:"日期",prop:"date"},
{label:"姓名",prop:"name"},
{label:"地址",prop:"address"}
],
//数据内容
tableData: [{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1517 弄'
}, {
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄'
}, {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄'
}]
}
},
components: {
VTable
}
}
</script>
简单的分装到此结束