效果示例
image.png
代碼示例
<!--一個(gè)典型的頁面再登,可以劃分為三個(gè)部分: template中的div元素贬媒,<script>標(biāo)簽內(nèi)的js腳本外臂,<style>標(biāo)簽中的樣式-->
<template>
<div class="block">
<span class="demonstration">二次開發(fā)代理商列表</span>
<el-button
type="primary"
icon="el-icon-plus"
@click="getAccountList"
style="float:right;">新增用戶</el-button>
<div>
<el-table :data="tableData" border style="width: 100%">
<el-table-column prop="id" label="唯一標(biāo)識" width="auto"></el-table-column>
<el-table-column label="真實(shí)姓名" width="auto">
<!--對于不能直接使用的數(shù)據(jù),可以使用template標(biāo)簽二次處理后册招,再綁定到DOM上-->
<template slot-scope="scope">
<span>{{scope.row.realName==='大佬'?'神秘人': scope.row.realName}}</span>
</template>
</el-table-column>
<el-table-column prop="mobile" label="手機(jī)號" width="auto"></el-table-column>
<el-table-column prop="note" label="備注" width="auto"></el-table-column>
<el-table-column prop="identityInfo" label="身份證號" width="auto"></el-table-column>
<el-table-column prop="updateTime" label="更新時(shí)間" width="auto"></el-table-column>
</el-table>
</div>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage4"
:page-sizes="[100, 200, 300, 400]"
:page-size="100"
layout="total, sizes, prev, pager, next, jumper"
:total="400">
</el-pagination>
</div>
</template>
<script>
export default {
//數(shù)據(jù)
//方法
name: 'agentList2',
//利用created()方法做到:首次打開頁面漓概,執(zhí)行一次查詢操作刀闷,把數(shù)據(jù)綁定的dom元素上
created(){
this.getAccountList()
},
methods: {
//開發(fā)步驟:
//1柳骄、在div中把變量綁定到dom元素上
//2团赏、在return返回中,聲明變量耐薯,用于接收接口的響應(yīng)數(shù)據(jù)舔清,
//3、條件觸發(fā)接口調(diào)用曲初,獲取接口的響應(yīng)數(shù)據(jù)体谒,并把響應(yīng)數(shù)據(jù)賦值給return中聲明的變量
getAccountList(){
console.log("執(zhí)行請求發(fā)送")
let obj = {}
//發(fā)送axios請求
this.$axios
.post(
this.$Api.getAccountList +
'?pageNo=' +
this.pageNo +
'&pageSize=' +
this.pageSize,
obj
)
.then(response => {
console.log("=============接口響應(yīng)數(shù)據(jù)========")
console.log(response.data.content.data)
if (response.data.code === 200) {
//把響應(yīng)數(shù)據(jù)賦值給tableData
this.tableData = response.data.content.data
}
})
},
handleSizeChange(val) {
console.log(`每頁 ${val} 條`);
},
handleCurrentChange(val) {
console.log(`當(dāng)前頁: ${val}`);
}
},
data() {
return {
currentPage1: 5,
currentPage2: 5,
currentPage3: 5,
currentPage4: 4,
tableData : [],
pageNo : 1,
pageSize : 10
};
}
}
</script>