前端开发实现的前台分页

前端开发实现的前台分页、搜索功能

技术类型vue

请求的数据格式

在这里插入图片描述

父组件的代码

<script>
import axios from 'axios'
import date from '@/utils/date.js'
import Search from '../compontents/Search'
import Pagination from '../compontents/Pagination'
export default {
  name: 'history',
  data () {
    return {
      tableData: [], // 需要显示的总数据
      currentPageData: [], // 需要当前页显示的数据
      total: 0, // 请求的数据总数
      CurrentPage: 1, // 当前页
      PageSize: 10, // 每页显示的条数
      PlaceholderTxt: '请输入浏览器名称或项目名称'  // 输入框的默认placeholder
    }
  },
  components: {
    Pagination,
    Search
  },
  methods: {
  	// 发送数据请求
    getDataList () {
      axios.get('请求地址')
        .then(this.handleGetDataListSucc)
    },
    // 初始的数据计算
    handleGetDataListSucc (res) {
      res = res.data
      if (res.code === 200 && res.object.data) {
        this.tableData = res.object.data.recordList
        this.total = this.tableData.length
        this.currentPageData = this.tableData.slice(0, 10)
      }
    },
    // 输入框搜索后的数据计算
    handlerInputChange (value) {
      let filterData = this.tableData.filter(item => item.projectName.indexOf(value) !== -1 || item.value.companyNameCN.indexOf(value) !== -1)
      this.currentPageData = filterData
      this.total = filterData.length
      this.CurrentPage = 1
    },
    // 格式化处理表格的时间数据格式
    formatterTableTime (time) {
      return date.format(time, 'yyyy-MM-dd hh:mm:ss')
    },
    // 点击分页时的数据计算
    handlerCurrentChange (value) {
      this.CurrentPage = value
      let start = (value - 1) * 10
      let end = value * 10
      this.currentPageData = this.tableData.slice(start, end)
    }
  },
  mounted () {
    this.getDataList()
  }
}
</script>

搜索框组件代码

<template>
    <div class="Search">
        <el-input
            :placeholder="PlaceholderTxt"
            clearable
            @change="InputValueChange"
            v-model="InputValue"
        >
            <el-button
                slot="append"
                icon="el-icon-search"
                @click="InputValueChange"
            ></el-button>
        </el-input>
    </div>
</template>
<script>
export default {
  name: 'Search',
  props: {
    PlaceholderTxt: {
      type: String,
      default: '请输入内容'
    }
  },
  data () {
    return {
      InputValue: ''
    }
  },
  methods: {
    InputValueChange () {
      this.$emit('InputChange', this.InputValue)
    }
  }
}
</script>
<style lang="less" scoped>
</style>

分页组件代码

<template>
  <div class="Pagination">
    <el-pagination
        background
        layout="prev, pager, next"
        :page-size="PageSize"
        :hide-on-single-page="true"
        :total="total"
        :current-page="CurrentPage"
        @current-change="CurrentChange"
        >
    </el-pagination>
  </div>
</template>
<script>
export default {
  name: 'Pagination',
  props: {
    total: Number,
    CurrentPage: Number,
    PageSize: Number
  },
  methods: {
    CurrentChange (e) {
      this.$emit('CurrentChange', e)
    }
  }
}
</script>
<style lang="less" scoped>
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值