之前一直接触都是原始的前端模型,jquery+bootstrap,冗杂的dom操作,繁琐的更新绑定。接触vue后,对前端MVVM框架有了全新的认识。本文是基于webpack+vue构建,由于之前的工作主要是基于java的服务端开发工作,对前端框架和组件的理解,不够深入,借此来记录在前端框架使用和构建中的点点滴滴。
此分页组件参照于bootstrap-datatable底部分页开发完成,相关参数增加自定义功能。
最终使用展现效果图如下,数据来源于cnodejs【https://cnodejs.org/】
底部分页组件主要由左侧当前数据项数量显示和右侧分页页码两部分组成。组件代码如下:
<template xmlns:v-on="http://www.w3.org/1999/xhtml"
xmlns:v-bind="http://www.w3.org/1999/xhtml">
<div class="page-bar">
<div class="page-size">
<div>
<select v-on:change="menuChange()" v-model="limit">
<option v-for="item in menu" v-bind:value="item">{{item}}</option>
</select>
记录/页,显示第 {{start}} 至 {{end}} 项记录,共 {{totalSize}} 项
</div>
</div>
<div class="page-con">
<ul>
<li><a v-on:click="firstClick()" v-bind:class="{ 'disabled': cur == 1}">首页</a></li>
<li><a v-on:click="preClick()" v-bind:class="{ 'disabled': cur == 1}">上一页</a></li>
<li v-for="per in pages" v-bind:class="{ 'active': cur == per}">
<a v-on:click="pageClick(per)">{{ per }}</a>
</li>
<li><a v-on:click="nextClick()" v-bind:class="{ 'disabled': cur == totalPage}">下一页</a></li>
<li><a v-on:click="lastClick()" v-bind:class="{ 'disabled': cur == totalPage}">尾页</a></li>
<li><a>共<i>{{totalPage}}</i>页</a></li>
</ul>
</div>
<div class="clear-both"></div>
</div>
</template>
<script>
import Ajax from '../ajax'
export default{
props: ['page-model'],
data () {
return {
// 初始页
cur: 1,
// 请求地址
url: this.pageModel.url "",
// 请求参数
param: this.pageModel.param "../assets/images/arrow.png") no-repeat scroll right center transparent;
padding-right: 15px;
padding-left: 15px;
padding-top: 2px;
padding-bottom: 2px;
}
select::-ms-expand {
display: none;
}
</style>
组建模块使用,
<template>
<Navbar></Navbar>
<div class="row">
<table class="table">
<thead>
<tr>
<th>标题</th>
<th width="20%">发布时间</th>
<th width="10%">作者</th>
<th width="10%">回复数</th>
<th width="10%">访问数</th>
</tr>
</thead>
<tbody>
<tr v-show="!tabelEmpty" v-for="item in dataList">
<td>{{item.title}}</td>
<td>{{item.create_at}}</td>
<td>{{item.author.loginname}}</td>
<td>{{item.reply_count}}</td>
<td>{{item.visit_count}}</td>
</tr>
<tr v-show="tabelEmpty" class="empty">
<td colspan="5">没有匹配的记录</td>
</tr>
</tbody>
</table>
</div>
<Pagebar :page-model="pageModel"></Pagebar>
</template>
<script>
import Navbar from '../components/navbar.vue'
import Pagebar from '../components/table-pagebar.vue'
export default {//这里是官方的写法,默认导出,ES6
components: {
Navbar,
Pagebar
},
data () {
return {
allArticle: "",
dataList: [],
pageModel: {
url: 'https://cnodejs.org/api/v1/topics',
menu: [5, 10, 20]
},
}
},
computed: {
tabelEmpty: function () {
if (this.dataList) {
return false;
} else {
return true;
}
}
},
events: {
refresh: function (e) {
this.dataList = e;
}
}
}
</script>
<style>
body, table {
font-size: 12px;
}
table {
table-layout: fixed;
empty-cells: show;
border-collapse: collapse;
width: 100%;
margin: 10px 0;
}
td {
height: 30px;
}
div.row {
margin-left: 15px;
margin-right: 15px;
}
h1, h2, h3 {
font-size: 12px;
margin: 0;
padding: 0;
}
.table {
border: 1px solid #ddd;
background: #fff;
}
.table thead tr {
background: #eee;
}
.table th {
background-repeat: repeat-x;
height: 30px;
text-align: left;
vertical-align: middle;
}
.table tr.empty {
text-align: center;
}
.table td, .table th {
border: 1px solid #ddd;
padding: 0 1em 0;
}
.table tr:nth-child(odd) td {
background-color: #f5f5f5;
}
</style>
本文已被整理到了《Vue.js前端组件学习教程》,欢迎大家学习阅读。
关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“vue分页组件table-pagebar使用实例解析”评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2025年10月28日
2025年10月28日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
