美文网首页
使用vue完成列表数据展示

使用vue完成列表数据展示

作者: 大风过岗 | 来源:发表于2021-01-18 09:24 被阅读0次

效果示例

image.png

代码示例



<!--一个典型的页面,可以划分为三个部分: template中的div元素,<script>标签内的js脚本,<style>标签中的样式-->
<template>
    <div class="block">
    <span class="demonstration">二次开发代理商列表</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="唯一标识"  width="auto"></el-table-column>
             <el-table-column   label="真实姓名"  width="auto">
                  <!--对于不能直接使用的数据,可以使用template标签二次处理后,再绑定到DOM上-->
                  <template slot-scope="scope">
                    <span>{{scope.row.realName==='大佬'?'神秘人': scope.row.realName}}</span>
                </template>
             </el-table-column>
             <el-table-column prop="mobile"  label="手机号"  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="更新时间"  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 {
       //数据
       //方法
        name: 'agentList2',

        //利用created()方法做到:首次打开页面,执行一次查询操作,把数据绑定的dom元素上
        created(){

          this.getAccountList()

        },
        methods: {
       //开发步骤:
       //1、在div中把变量绑定到dom元素上
       //2、在return返回中,声明变量,用于接收接口的响应数据,
       //3、条件触发接口调用,获取接口的响应数据,并把响应数据赋值给return中声明的变量
        getAccountList(){
        console.log("执行请求发送")
        let obj = {}

            //发送axios请求
             this.$axios
        .post(
          this.$Api.getAccountList +
            '?pageNo=' +
            this.pageNo +
            '&pageSize=' +
            this.pageSize,
          obj
        )
        .then(response => {
            console.log("=============接口响应数据========")
            console.log(response.data.content.data)
          if (response.data.code === 200) {
             //把响应数据赋值给tableData
             this.tableData = response.data.content.data
          }
        })
        },  
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
        }
    },
    data() {
      return {
        currentPage1: 5,
        currentPage2: 5,
        currentPage3: 5,
        currentPage4: 4,
        tableData   : [],
        pageNo      : 1,
        pageSize    : 10
      };
    }
    }
  </script>

相关文章

网友评论

      本文标题:使用vue完成列表数据展示

      本文链接:https://www.haomeiwen.com/subject/tkqwaktx.html