当前位置:网站首页>将数据库拿到的数据渲染到elementUI 中的table中去
将数据库拿到的数据渲染到elementUI 中的table中去
2022-07-28 04:15:00 【_rosy】
其实关键只有两点,一是你能够通过接口拿到数据库里面的数据,二是把你table里面的prop与数据库里面的字段名相等,就是把你想要那个参数展示哪个数据库里面的子段信息,你就把prop="字段名"
代码:
<template>
<div class="goods">
<!-- 搜索区域 -->
<div class="header">
<el-input v-model="input" placeholder="请输入内容"></el-input>
<el-button type="primary">查询</el-button>
<el-button type="primary">添加</el-button>
</div>
<!-- 表格区域展示视图 -->
<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="商品ID" width="100px">
</el-table-column>
<el-table-column prop="title" label="商品名称" width="100px">
</el-table-column>
<el-table-column width="100px" prop="price" label="商品价格">
</el-table-column>
<el-table-column width="100px" prop="num" label="商品数量">
</el-table-column>
<el-table-column
width="120px" prop="category" label="规格类目">
</el-table-column>
<el-table-column prop="image" label="商品图片">
</el-table-column>
<el-table-column prop="sellPoint" label="商品买点">
</el-table-column>
<el-table-column prop="descs" label="商品描述">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleEdit(scope.$index, scope.row)">编辑</el-button>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 分页 -->
</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>

注意观察红色代码:
<template>
<div class="goods">
<!-- 搜索区域 -->
<div class="header">
<el-input v-model="input" placeholder="请输入内容"></el-input>
<el-button type="primary">查询</el-button>
<el-button type="primary">添加</el-button>
</div>
<!-- 表格区域展示视图 -->
<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="商品ID" width="100px">
</el-table-column>
<el-table-columnprop="title" label="商品名称" width="100px">
</el-table-column>
<el-table-column width="100px" prop="price" label="商品价格">
</el-table-column>
<el-table-column width="100px" prop="num" label="商品数量">
</el-table-column>
<el-table-column
width="120px" prop="category" label="规格类目">
</el-table-column>
<el-table-column prop="image" label="商品图片">
</el-table-column>
<el-table-column prop="sellPoint" label="商品买点">
</el-table-column>
<el-table-column prop="descs" label="商品描述">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-button
size="mini"
@click="handleEdit(scope.$index, scope.row)">编辑</el-button>
<el-button
size="mini"
type="danger"
@click="handleDelete(scope.$index, scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 分页 -->
</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>
边栏推荐
- 7/27(板子)染色法判定二分图+求组合数(递推公式)
- Analysis of static broadcast transmission process
- Convert py file to exe executable file
- Notes to subject 2
- Is there a bonus period for robot engineering
- Learn regular expressions (regexp)
- 【无标题】
- [untitled]
- The unsatisfied analysis of setup and hold timing is the solution
- 21天,胖哥亲自带你玩转OAuth2
猜你喜欢

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

RT thread changes the print serial port (add other functions on the basis of BSP)

Do Netease and Baidu have their own tricks for seizing the beach AI learning machine?

How to select reliable securities analysts?

The simulation test disconnects the server from the public network

servlet使用

Work fishing clock simulator wechat applet source code

Fedformer MOE module

Classification cluster analysis

VAE generation model (with VAE implementation MNIST code)
随机推荐
glusterfs 文件未挂载,权限: r-s
R notes mice
Go structure
When import is introduced, sometimes there are braces, sometimes there are no braces. How should we understand this?
Go grpc: a solution of connection reset by peer
Un7.27: how to successfully build a ruoyi framework project in idea?
Do Netease and Baidu have their own tricks for seizing the beach AI learning machine?
上班摸鱼打卡模拟器微信小程序源码
The State Administration of market supervision exposes typical cases of food safety
Information system project manager (2022) - key content: Project Risk Management (11)
月薪28K学员 自动化测试经验分享
Citrix virtual desktop tcp/udp transmission protocol switching
Construction and use of FTP server and NFS server
[reach out to Party welfare] the easiest way to scan the H5 page in wechat
Thoroughly understand the sharing function in wechat games
Error no matching function for call to 'std:: exception:: exception (const char [15])' problem solving
Regression - linear regression
Information system project manager (2022) - key content: Project Procurement Management (12)
RN interface jump description
[performance optimization methodology series] III. core idea of performance optimization (2)