基於vue的分頁插件


相信大家用過很多jquery的分頁插件,那這次就用一用基於vue的分頁插件。

這里的環境用的是springboot

首先要引入pagehelper的jar文件,版本是1.2.3,配置文件也需要配置一下


 

核心代碼:

 DAO層

接口:

1 List<Article> selectAll();

mapper文件:

只需要寫一個簡單的查詢即可。

1 <select id="selectAll" resultMap="ResultMapWithBLOBs">
2     select <include refid="Base_Column_List"/> from article
3   </select>

Service層:

接口:

1 PageInfo<Article> selectAll(int pageNum,int pageSize);

實現:

1    @Override
2     public PageInfo<Article> selectAll(int pageNum,int pageSize) {
3         Page<Article> page = PageHelper.startPage(pageNum, pageSize);
4         articleMapper.selectAll();
5         return page.toPageInfo();
6     }

Controller層:

1 @RequestMapping("/selectAll")
2     @ResponseBody
3     public Object selectArticleAll(@RequestParam(required = true,defaultValue = "0")int pageNum,
4                                    @RequestParam(required = true,defaultValue = "3")int pageSize){
5         PageInfo<Article> articlePageInfo = articleService.selectAll(pageNum, pageSize);
6         return articlePageInfo;
7     }

前台代碼:

引入所需的js和css文件:

1 <link rel="stylesheet" th:href="@{/css/zpageNav.css}"/>
2 <script th:src="@{/js/vue.js}"></script>
3 <script th:src="@{/js/zpageNav.js}"></script>
4 <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>

點這里下載

html:

<div id="container">

    <article class="article" v-for="item in articleList">
        <time>{{item.time}}</time>
        <h2 class="title"><a href="article?id=${article.id}">{{item.title}}</a></h2>
        <span><i>{{item.keywords}}</i></span>
        <section class="article-content markdown-body">
            <blockquote>
                <p>{{item.desci}}</p>
            </blockquote>
            ......
        </section>
        <footer>
            <a href="article?id=${article.id}">閱讀全文</a>
        </footer>
    </article>
    
    <!--分頁條的占位-->
    <zpagenav v-bind:page="page" v-bind:page-size="pageSize" v-bind:total="total" v-bind:max-page="maxPage" v-on:pagehandler="pageHandler"></zpagenav>
</div>

vue:

 1 <script>
 2     var vm=new Vue({
 3         el:"#container",
 4         data:{
 5             articleList:[],
 6             page:1,   //顯示的是哪一頁
 7             pageSize:5,  //頁面顯示的數據條數
 8             total:100,  //總記錄數
 9             maxPage:9,  //總頁數
10         },
11         methods:{
12             //跳轉到page頁
13             pageHandler:function (page) {
14                 this.page=page; //修改顯示的頁數page
15                 var params={"pageNum":page,"pageSize":this.pageSize};
16                 this.$http.post("/article/selectAll",params,{emulateJSON:true}).then(
17                     function (res) {
18                         this.articleList=res.data.list;
19                         this.total=res.data.total;
20                         this.maxPage=res.data.pages;
21                     },
22                     function (res) {
23                         console.log(res);
24                     }
25                 )
26             }
27         },
28         created:function () {
29             this.pageHandler(1);
30         }
31     });
32 </script>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM