<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>图书商城-图书列表</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <link rel="stylesheet" href="/BookShopSystem_war/layui/css/layui.css"> <link rel="stylesheet" href="/BookShopSystem_war/static/css/index.css"> <script src="https://cdn.bootcss.com/vue/2.5.16/vue.min.js"></script> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="app"> <div class="layui-container"> <div class="hot-sell" v-if="bookAll.length > 0"> <div class="layui-row layui-col-space20"> <table> <tr> <td v-for="(bk,index) in currentBookAll" :key="index" class="layui-col-xs2" style="margin-left: 30px"> <a :href="'detail?id='+bk.bookId" class="text"> <div><img :src="'/BookShopSystem_war/' + bk.image1"></div> <p>{{bk.bookName}}</p> <p class="price">¥{{bk.bookPrice}}</p> </a> </td> </tr> </table> </div> </div> </div> <div id="houseList"></div> </div> <!-- 引入尾部footer.html --> <iframe src="footer.html" frameborder="0" scrolling="no" width="100%" height="245px"></iframe> </div> <script src="/BookShopSystem_war/layui/layui.js"></script>这是完整的html代码,请结合你给出的分页功能整合出完整的代码
时间: 2023-08-14 12:25:19 浏览: 245
好的,以下是结合分页功能的完整代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图书商城-图书列表</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="/BookShopSystem_war/layui/css/layui.css">
<link rel="stylesheet" href="/BookShopSystem_war/static/css/index.css">
<script src="https://cdn.bootcss.com/vue/2.5.16/vue.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
<div class="layui-container">
<div class="hot-sell" v-if="bookAll.length > 0">
<div class="layui-row layui-col-space20">
<table>
<tr>
<td v-for="(bk,index) in currentBookAll" :key="index" class="layui-col-xs2" style="margin-left: 30px">
<a :href="'detail?id='+bk.bookId" class="text">
<div><img :src="'/BookShopSystem_war/' + bk.image1"></div>
<p>{{bk.bookName}}</p>
<p class="price">¥{{bk.bookPrice}}</p>
</a>
</td>
</tr>
</table>
</div>
</div>
<div class="layui-row">
<div class="layui-col-md12">
<div id="pagination"></div>
</div>
</div>
</div>
<div id="houseList"></div>
<!-- 引入尾部footer.html -->
<iframe src="footer.html" frameborder="0" scrolling="no" width="100%" height="245px"></iframe>
</div>
<script src="/BookShopSystem_war/layui/layui.js"></script>
<script>
layui.use('laypage', function(){
var laypage = layui.laypage;
var vm = new Vue({
el: '#app',
data: {
bookAll: [],
current: 1,
totalPage: 1,
currentBookAll: []
},
mounted: function() {
var _this = this;
axios.get('/BookShopSystem_war/book/all')
.then(function(response) {
_this.bookAll = response.data;
_this.totalPage = Math.ceil(_this.bookAll.length / 10);
_this.currentBookAll = _this.bookAll.slice(0, 10);
laypage.render({
elem: 'pagination',
count: _this.bookAll.length,
curr: _this.current,
limit: 10,
layout: ['prev', 'page', 'next', 'skip'],
jump: function(obj, first){
if(!first){
_this.currentBookAll = _this.bookAll.slice((obj.curr-1)*obj.limit, obj.curr*obj.limit);
}
}
});
})
.catch(function(error) {
console.log(error);
});
}
});
});
</script>
</body>
</html>
注意:这里的分页功能使用了 layui 的 laypage 组件,需要在页面中引入 layui.js 和 layui.css,并且需要在 Vue 的 mounted 钩子函数中调用 laypage.render() 方法来渲染分页组件。同时,需要注意在分页回调函数中更新当前显示的数据。
阅读全文