当前位置 博文首页 > IT13333的博客:vue 项目 创建表格
创建一个组件 直接复制下面代码 粘贴 需要的页面引入即可
<template>
<div class="about">
<!-- <div v-for="(item,index) in list" :key="index"> -->
<table id="table" border="1" cellspacing="0" cellpadding="15">
<thead >
<tr >
<th>编号</th>
<th>姓名</th>
<th>电话</th>
<th>邮箱</th>
<th>社交账号</th>
<th>需求</th>
</tr>
</thead >
<tbody >
<tr v-for="(item,index) in list" :key="index">
<td>{{index+1}}</td>
<td>{{item.username}}</td>
<td>{{item.phone}}</td>
<td>{{item.email}}</td>
<td>{{item.sjzh}}</td>
<td>{{item.xuqiu}}</td>
<!-- <td><button @click="remove(index)">移除</button></td> -->
</tr>
<tr>
<!-- <td></td>
<td><input id="" v-model="username"></td>
<td><input id="age" v-model="phone"></td>
<td><input id="age" v-model="email"></td>
<td><input id="age" v-model="sjzh"></td>
<td><input id="age" v-model="xuqiu"></td> -->
<!-- <td><button @click="insert">添加</button></td> -->
</tr>
</tbody>
</table>
<td>
</td>
</div>
<!-- </div> -->
</template>
<script>
import {getmassege} from "../utils/api"
export default {
name:"submitinfo",
data() {
return {
username:"",
phone:"",
email:"",
sjzh:"",
xuqiu:"",
list:[],
};
},
methods:{
insert:function(){
this.list.push(this.list)
},
remove:function(index){
this.list.splice(index,1)
}
},
created(){
getmassege(1,50).then(res=>{
console.log(res)
console.log(1101)
this.list=res.records
})
}
};
</script>
<style lang="less" scoped>
.about{
display: flex;
justify-content: center;
}
</style>
cs