当前位置:网站首页>Render the data obtained from the database to the table in elementui
Render the data obtained from the database to the table in elementui
2022-07-28 04:25:00 【_ rosy】
In fact, there are only two key points , First, you can get the data in the database through the interface , Second, put you table Inside prop Equal to the field name in the database , It is to show the sub segment information in which database you want the parameter , You put prop=" Field name "
Code :
<template>
<div class="goods">
<!-- Search area -->
<div class="header">
<el-input v-model="input" placeholder=" Please enter the content "></el-input>
<el-button type="primary"> Inquire about </el-button>
<el-button type="primary"> add to </el-button>
</div>
<!-- Table area display view -->
<div class="wrapper">
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column type="selection" width="55">
</el-table-column>
<el-table-column prop="id" label=" goods ID" width="100px">
</el-table-column>
<el-table-column prop="title" label=" Name of commodity " width="100px">
</el-table-column>
<el-table-column width="100px" prop="price" label=" commodity price ">
</el-table-column>
<el-table-column width="100px" prop="num" label=" The number ">
</el-table-column>
<el-table-column
width="120px" prop="category" label=" Specification category ">
</el-table-column>
<el-table-column prop="image" label=" Commodity images ">
</el-table-column>
<el-table-column prop="sellPoint" label=" Buy goods ">
</el-table-column>
<el-table-column prop="descs" label=" Commodity Description ">
</el-table-column>
<el-table-column label=" operation ">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleEdit(scope.$index, scope.row)"> edit </el-button>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)"> Delete </el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- Pagination -->
</div>
</template>
<script>
// import axios from 'axios'
export default {
name: 'GooDs',
data() {
return {
input: '',
tableData:[]
}
},
components: {},
methods: {
handleEdit(index, row) {
console.log(index, row);
},
handleDelete(index, row) {
console.log(index, row);
}
},
created(){
console.log(this.$api)
// axios.get('http://localhost:3001/api/projectList?page=1').then(res => {
// console.log(res);
// })
this.$api.getGoodsList({
page:1
}).then(res=>{
console.log(res.data)
if(res.data.status===200){
this.tableData=res.data.data
}
})
}
}
</script>
<style lang="less" scoped >
.goods {
margin: 20px;
}
.header {
height: 60px;
display: flex;
button {
height: 40px;
margin-left: 20px;
}
margin: 20px,0;
}
.wrapper{
display: block;
margin:20px,0;
}
</style>

Pay attention to the red code :
<template>
<div class="goods">
<!-- Search area -->
<div class="header">
<el-input v-model="input" placeholder=" Please enter the content "></el-input>
<el-button type="primary"> Inquire about </el-button>
<el-button type="primary"> add to </el-button>
</div>
<!-- Table area display view -->
<div class="wrapper">
<el-table
:data="tableData"
border
style="width: 100%">
<el-table-column type="selection" width="55">
</el-table-column>
<el-table-columnprop="id" label=" goods ID" width="100px">
</el-table-column>
<el-table-columnprop="title" label=" Name of commodity " width="100px">
</el-table-column>
<el-table-column width="100px" prop="price" label=" commodity price ">
</el-table-column>
<el-table-column width="100px" prop="num" label=" The number ">
</el-table-column>
<el-table-column
width="120px" prop="category" label=" Specification category ">
</el-table-column>
<el-table-column prop="image" label=" Commodity images ">
</el-table-column>
<el-table-column prop="sellPoint" label=" Buy goods ">
</el-table-column>
<el-table-column prop="descs" label=" Commodity Description ">
</el-table-column>
<el-table-column label=" operation ">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleEdit(scope.$index, scope.row)"> edit </el-button>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)"> Delete </el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- Pagination -->
</div>
</template>
<script>
// import axios from 'axios'
export default {
name: 'GooDs',
data() {
return {
input: '',
tableData:[]
}
},
components: {},
methods: {
handleEdit(index, row) {
console.log(index, row);
},
handleDelete(index, row) {
console.log(index, row);
}
},
created(){
console.log(this.$api)
// axios.get('http://localhost:3001/api/projectList?page=1').then(res => {
// console.log(res);
// })
this.$api.getGoodsList({
page:1
}).then(res=>{
console.log(res.data)
if(res.data.status===200){
this.tableData=res.data.data
}
})
}
}
</script>
<style lang="less" scoped >
.goods {
margin: 20px;
}
.header {
height: 60px;
display: flex;
button {
height: 40px;
margin-left: 20px;
}
margin: 20px,0;
}
.wrapper{
display: block;
margin:20px,0;
}
</style>
边栏推荐
- 高数_第4章__曲线积分_习题解法
- 上班摸鱼打卡模拟器微信小程序源码
- Chinese Remainder Theorem of X problem
- 重要的 SQL Server 函数 - 日期函数
- C # cross thread refresh foreground UI
- 【实战】使用 Web Animations API 实现一个精确计时的时钟
- un7.27:如何在idea中成功搭建若依框架项目?
- 关系数据库事务中的对象锁定
- ServletContext、request、response
- What is the account opening process of qiniu business school? Is it safe?
猜你喜欢

Seamless support for hugging face community, colossal AI low-cost and easy acceleration of large model

There are so many ways to view the web source code! Do you know?

Un7.27: how to successfully build a ruoyi framework project in idea?

上班摸鱼打卡模拟器微信小程序源码

Virtual machine class loading mechanism

Go结构体

Learn regular expressions (regexp)

重要的 SQL Server 函数 - 日期函数

Information system project manager (2022) - key content: Project Risk Management (11)
![[mathematical modeling] Based on MATLAB seismic exploration Marmousi model [including Matlab source code, 1977]](/img/fd/6b261670c12e4d89c27364bcdf2a02.jpg)
[mathematical modeling] Based on MATLAB seismic exploration Marmousi model [including Matlab source code, 1977]
随机推荐
[performance optimization methodology series] III. core idea of performance optimization (2)
Campus stray cat information recording and sharing applet source code
空间复杂度计算超全整理!!(一起手撕复杂度计算
RT thread changes the print serial port (add other functions on the basis of BSP)
RT-Thread改变打印串口(在BSP的基础上添加其他功能)
What to do when encountering slow SQL? (next)
Null security and exception
Work fishing clock simulator wechat applet source code
【伸手党福利】微信中h5网页调起扫一扫最简单的方法
Idea2022 change the local warehouse and configure Alibaba cloud central warehouse
Learn regular expressions (regexp)
7/27(板子)染色法判定二分图+求组合数(递推公式)
2022-7-27 顾宇佳 学习笔记
21 days, fat brother personally takes you to play oauth2
[untitled]
Filters, interceptors, listeners
Power consumption: leakage power
【YOLOv5实战5】基于YOLOv5的交通标志识别系统-YOLOv5整合PyQt5
【牛客】求1+2+3+...+n
un7.27:redis数据库常用命令。