vue手写分页

效果图如下:

 样式可以自己随便设置

html代码:

                <div class="page-bar">
                  <ul>
                    <li>
                      <a style="border: none;padding: 6px 8px;"
                        >总共<i>{{ total }}</i
                        >个项目</a
                      >
                    </li>
                    <li v-if="cur>1">
                      <a v-on:click="cur--,pageClick()"><</a>
                    </li>
                    <li v-if="cur==1"><a class="banclick"><</a></li>
                    <li
                      v-for="index in indexs"
                      v-bind:class="{ 'active': cur == index}"
                    >
                      <a v-on:click="btnClick(index)">{{ index }}</a>
                    </li>
                    <li v-if="cur!=all">
                      <a v-on:click="cur++,pageClick()">></a>
                    </li>
                    <li v-if="cur == all"><a class="banclick">></a></li>
                  </ul>
                </div>

css代码:

/*分页*/
.page-bar{
  width: 540px;
  height: 30px;
  margin: 40px 20px 30px 555px;
  margin-top: 10px;
  margin-bottom: 30px;
  position: absolute;
  bottom: 10px;
  }
  ul,li{
  margin: 0px;
  padding: 0px;
  }
  li{
  list-style: none
  }
  .page-bar li:first-child>a {
  margin-left: 0px
  }
  .page-bar a{
  border: 1px solid #ddd;
  text-decoration: none;
  position: relative;
  float: left;
  padding: 6px 12px;
  margin-left: -1px;
  line-height: 1.42857143;
  color: #5D6062;
  cursor: pointer;
  margin-right: 4px;
  }
  .page-bar a:hover{
  background-color: #eee;
  }
  .page-bar a.banclick{
  cursor:not-allowed;
  }
  .page-bar .active a{
  color: #fff;
  cursor: default;
  background-color: #C98743;
  border-color: #C98743;
  }
  .page-bar i{
  font-style:normal;
  margin: 0px 4px;
  font-size: 12px;
  }

js代码:

     data{
        all: 0, //总页数
          cur: 1, //当前页码
          totalPage: 5, //当前条数
          total:0,//总数
        }
   





//这个是分页数据的接口,替换成自己的数据接口就行
             zhengdanList(index,demandtypeDate){
            const _this = this
            const params = {
              page: index||1,
              size: this.totalPage,
              status: demandtypeDate||1,
            }
            $.ajax({
              url: `https://common-api${getEnv()}.homedo.com/bff-common-api/solicitationFor/singleTable`,
              type: 'POST',
              headers:{ticket:$HMD$.Cookie('ticket')},
              data: JSON.stringify(params),
              dataType: 'json',
              contentType: 'application/json',
              success: function (res) {
                if(res.respCode == '0000' && res.data && res.data.items){
                  _this.demandList = res.data.items
                  _this.total = res.data.count
                  _this.all = Math.ceil(res.data.count / res.data.size) //总页数
                  _this.cur = res.data.page //当前页码
                  _this.totalPage = res.data.size //当前条数
                }
              },

           //分页
          btnClick(data) {
            //页码点击事件
            if (data != this.cur) {
              this.cur = data
            }
            //根据点击页数请求数据
            this.tab2(this.cur.toString())
          },
          pageClick() {
            //根据点击页数请求数据
            this.tab2(this.cur.toString())
          },

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值