Vue实现简易翻页效果源码分享源码如下:
<html>
<head>  <meta charset="UTF-8">
<title>slidePage</title>
<script src="cdn.jsdelivr/npm/vue@2.5.17/dist/vue.js"></script>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.container {
width: 100%;
margin: 0 auto;
text-align: center;
}
.content{
font-size: 400px
}
.leftBtn{
width: 45px;
height: 45px;
margin-right: 15px;
}
.rightBtn{
width: 45px;
height: 45px;
margin-left: 15px;
}
</style>
</head>
<body>
<div id='root'>
<div v-if="numberArr.length == 0">{{showMessage}}</div>
有没有什么网站分享源码
<div class="container" v-for="(item, index) in getCurPageContent(numberArr, curPage, itemNumPerPage)" :key="index">  <div class="content">{{item}}</div>
<div class="pageButtonList">
<button class="leftBtn" @click="handleClick('leftBtn')"><</button>
<span class="pagination">{{curPage}}/{{totalPage}}</span>
<button class="rightBtn" @click="handleClick('rightBtn')">></button>
</div>
</div>
</div>
<script>
new Vue({
el: "#root",
data(){
return {
showMessage: 'No number',
content:'',
numberArr: [1, 2, 3, 4],
curPage: 1,
totalPage: 1,
itemNumPerPage: 1
}
},
mounted() {
this.init()
},
methods:{
init(){
},
getCurPageContent: function(numberArr, curPage, itemNumPerPage){
return numberArr.filter(function(element, index){
if(index >= (curPage -1)* itemNumPerPage && index < curPage *itemNumPerPage){
return true
}else{
return false
}
})
},
handleClick: function(arg){
if(arg == 'leftBtn'){
this.curPage = this.curPage > 1 ? --this.curPage : alPage
}else if (arg == 'rightBtn'){
this.curPage = this.curPage < alPage ? ++this.curPage: 1
}
}
// handleLeftClick: function(){
//  if(this.curPage > 1){
//    this.curPage --
//  }else{
//    this.curPage = alPage
//  }
// },
// handleRightClick: function(){
//  if(this.curPage < alPage){
//    this.curPage ++
/
/  }else{
//    this.curPage = 1
//  }
// }
}
})
</script>
</body>
</html>
效果如下所⽰,点击左右能切换页⾯:
总结
以上所述是⼩编给⼤家介绍的Vue实现简易翻页效果源码分享,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。在此也⾮常感谢⼤家对⽹站的⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。