git checkout - b goods_list
git push - u origin goods_list
1. 初始化List.vue并 添加路由
< template>
< div>
< ! -- 面包屑导航区域 -- >
< el- breadcrumb separator- class = "el-icon-arrow-right" >
< el- breadcrumb- item : to= "{ path: '/home' }" > 首页< / el- breadcrumb- item>
< el- breadcrumb- item> 商品管理< / el- breadcrumb- item>
< el- breadcrumb- item> 商品列表< / el- breadcrumb- item>
< / el- breadcrumb>
< ! -- 卡片视图区域 -- >
< el- card>
< ! -- 搜索与添加区域 -- >
< ! -- el- row el- col 实现栅格布局 -- >
< ! -- Row 组件 提供 gutter 属性来指定每一栏之间的间隔,默认间隔为 0
< el- col> 里面有span属性,span为x,则分成 24 / x 列(栅格布局一行分为24 栏) -- >
< el- row : gutter= "30" >
< el- col : span= "8" >
< el- input placeholder= "请输入内容" >
< el- button slot= "append" icon= "el-icon-search" > < / el- button>
< / el- input>
< / el- col>
< el- col : span= "4" >
< el- button type= "primary" > 添加商品< / el- button>
< / el- col>
< / el- row>
< / el- card>
< / div>
< / template>
2. 商品列表table
2.1 获取数据
data ( ) {
return {
queryInfo : {
query : '' ,
pagenum : 1 ,
pagesize : 10
} ,
goodsList : [ ] ,
total : 0
}
} ,
created ( ) {
this . getGoodsList ( )
} ,
methods : {
async getGoodsList ( ) {
const {
data : result } = await this . $http. get ( 'goods' , {
params : this . queryInfo } )
if ( result. meta. status !== 200 ) {
return this . $message. error ( '获取商品列表失败!' )
}
this . $message. success ( '获取商品列表成功!' )
console. log ( result. data)
this . goodsList = result. data. goods
this . total = result. data. total
}
}
2.2 显示数据
< ! -- 商品table表格区域 -- >
< el- table : data= "goodsList" border stripe>
< el- table- column type= "index" > < / el- table- column>
< el- table- column label= "商品名称" prop= "goods_name" > < / el- table- column>
< el- table- column label= "商品价格(元)" prop= "goods_price" width= "90px" > < / el- table- column>
< el- table- column label= "商品重量" prop= "goods_weight" width= "70px" > < / el- table- column>
< el- table- column label= "创建时间" prop= "add_time" width= "140px" > < / el- table- column>
< el- table- column label= "操作" width= "130px" >
< template>
< el- button type= "primary" icon= "el-icon-edit" size= "mini" > < / el- button>
< el- button type= "danger" icon= "el-icon-delete" size= "mini" > < / el- button>
< / template>
< / el- table- column>
< / el- table>
2.3 使用全局过滤器Vue.filter自定义格式化时间
Vue. filter ( 'dataFormat' , function ( originVal ) {
const dt = new Date ( originVal)
const y = dt. getFullYear ( )
const m = ( dt. getMonth ( ) + 1 + '' ) . padStart ( 2 , '0' )
const d = ( dt. getDate ( ) + '' ) . padStart ( 2 , '0' )
const hh = ( dt. getHours ( ) + '' ) . padStart ( 2 , '0' )
const mm = ( dt. getMinutes ( ) + '' ) . padStart ( 2 , '0' )
const ss = ( dt. getSeconds ( ) + '' ) . padStart ( 2 , '0' )
return ` ${
y} - ${
m} - ${
d} ${
hh} : ${
mm} : ${
ss} `
} )
< el- table- column label= "创建时间" prop= "add_time" width= "140px" >
< template slot- scope= "scope" >
{
{
scope. row. add_time | dateFormat} }
< / template>
< / el- table- column>
3. 商品列表分页管理功能
< ! -- 分页区域 -- >
< el- pagination @size- change= "handleSizeChange" @current- change= "handleCurrentChange"
: current- page= "queryInfo.pagenum" : page- sizes= "[5, 10, 15, 20]" : page- size