美文网首页
2018-12-20 用vue.js的v-for写了个简单的分页

2018-12-20 用vue.js的v-for写了个简单的分页

作者: 庚_ | 来源:发表于2018-12-20 17:55 被阅读0次

写了一个简单的分页样式,主要是v-for的用法,然后就是用methods添加函数让当前页面等于点击的那个数字,然后通过判断让class显示。大多是vue教程中的知识,但是还是看了很多个例子才明白。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>vue</title>
<script src="./vue.js"></script>
<style>
    #app{
        margin-top: 120px;
    }
    .pagenav{
        margin: 10px;
     padding: 5px;
        border: 1px solid #CCCCCC;
        font-size: 12px;
    }
    .selectedpage{
        background-color: #CCCCCC;
    }
</style>
</head>
<body>
<div id="app">
 <span class="pagenav" v-bind:class="{ 'selectedpage':  item==curpage  }" v-for=' item  in sum' v-on:click='pageclick(item)'>{{item}}</span>
</div>
<script>
 
 var app = new Vue({
     el:'#app',
     data:{
         sum:10,
         curpage:'1'
     },
     methods:{
         pageclick: function(item){
             this.curpage=item
         }
     }
 })
</script>
</body>
</html>

相关文章

网友评论

      本文标题:2018-12-20 用vue.js的v-for写了个简单的分页

      本文链接:https://www.haomeiwen.com/subject/csxukqtx.html