• Vue elementUi input查询、el-table数据表 、el-pagination分页的使用


    <template>
    <div>
    <el-input v-model="input" placeholder="请输入关键字"></el-input>
    <el-table
    ref="multipleTable"
    :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)"
    tooltip-effect="dark"
    style=" 100%"
    @selection-change="handleSelectionChange"
    >
    <el-table-column type="selection" width="55"></el-table-column>
    <el-table-column label="日期" width="120">
    <template slot-scope="scope">{{ scope.row.date }}</template>
    </el-table-column>
    <el-table-column prop="name" label="姓名" width="120"></el-table-column>
    <el-table-column prop="address" label="地址" show-overflow-tooltip></el-table-column>
    </el-table>
    <el-pagination
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    :current-page="currentPage"
    :page-sizes="[4, 8]"
    :page-size="2"
    layout="total, sizes, prev, pager, next, jumper"
    :total="total"
    ></el-pagination>
    </div>
    </template>
    <script>
    export default {
    data() {
    return {
    input: "",
    tableList: null,
    currentPage: 1,
    pageSize: 8,
    };
    },
    watch: {
    tableData() {
    this.currentPage = 1;
    }
    },
    computed: {
    //表名列表中搜索
    tableData() {
    var search = this.input.toString().toLowerCase(); //将用户输入的值变字符串并小写
    if (search) {
    return this.tableList.filter(function(dataNews) {      // 如果用户输入将this.tableList数组过滤返回this.tableList的key值数组,然后在key的数组中将key进行转化成字符串变小写再转变的数组中是否有用户输入的key值,如果有返回this.tableList的key 作为this.tableData的值
    return Object.keys(dataNews).some(function(key) {
    return (
    String(dataNews[key])
    .toLowerCase()
    .indexOf(search) > -1
    );
    });
    });
    }
    return this.tableList;
    },
    total() {
    return this.tableData.length;
    }
    },
    mounted() {
    console.log(this.tableData);
    this.$axios.get("/datatable.json").then((res, rej) => {
    this.tableList = res.data.data.tableData;
    });
    },
    methods: {
    handleSelectionChange(val) {
    this.multipleSelection = val;
    console.log(val);
    },
    handleSizeChange(val) {
    this.pageSize = val;
    console.log(this.pa)
    },
    handleCurrentChange(val) {
    this.currentPage = val;
    console.log(val);
    }
    }
    };
    </script>
     
    这里tableData是从后台获取的数据,在计算属性上定义通过this.tableList赋值,这里Input赋值关键字查询,分页的当前页通过handleCurrentChange方法获取,分页的每页显示个数选择器通过handleSizeChange来获取,这里tableData通过tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)方式来获取
     



  • 相关阅读:
    根据指定的编码格式返回请求的参数集合
    【C++ 学习笔记】 size_t 和 int
    C++ 编译错误
    【Flex】 加载Gif文件
    【C++ 学习笔记】:STLmap
    【C++ 学习笔记】:MFC(细节部分)
    小卡的土豆园开园了~
    [论文笔记] A novel reduction approach to analyzing QoS of workflow processes (Concurrency and Computation: Practice and Experience, 2009)
    [论文收集] WWW2008 相关或感兴趣的论文
    [论文泛读] Accurate and efficient stochastic reliability analysis of composite services using their compact Markov reward model representations (SCC, 2007)
  • 原文地址:https://www.cnblogs.com/zhx119/p/11208793.html
Copyright © 2020-2023  润新知