<div v-for="(data,index) in list" :key="index" class="speCific" :data-id="data.bookId"> <div class="xzWxz"> <b><img :src="/BookShopSystem_war/cart/xzwxz.png"></b> </div> <div class="xzSp"> <img :src="'/BookShopSystem_war/' + data.image1"> <div class="xzSpIn"> <h3 class="font16 c_33 font100">{{ data.bookName }}</h3> <h3 class="font16 c_33 font100">{{ data.bookAuthor }}</h3> <h3 class="font16 c_33 font100">{{ data.bookPublish }}</h3> </div> </div> <div class="xzJg"> ¥<font>{{ data.price }}</font> </div> <div class="xzSl"> <div class="xzSlIn"> <b class="Amin">减</b> <input type="text" :value="data.num" readonly class="cOnt"> <b style="border-right: none;border-left:1px solid #ddd;" class="Aadd">加</b> </div> </div> <div class="xzXj">¥{{data.total}}<font></font></div> <div class="xzSz"> <div class="xzCzIn"> <a href="javascript:void(0)" class="Dels" :data-id="data.bookId">删除</a> <!-- <a href="javascript:void(0)" class="Dels" @click="deleteItem(index)">删除</a>--> </div> </div> </div>new Vue({ el: '#app', data: { userId: '', list: [] // list: [ // {userId:null,bookName:"图书1",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:2}, // {userId:null,bookName:"图书2",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:1}, // {userId:null,bookName:"图书3",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:2} // ] }, //选择或不选择一项 $(".xzWxz").click(function () { if ($(this).hasClass("on")) { $(this).removeClass("on"); } else { $(this).addClass("on"); } var ty = $(".xzWxz.on").length; $(".sXd1").find("font").html(ty); if (ty == es) { $(".ifAll").addClass("on"); } else { $(".ifAll").removeClass("on"); } jsZj(); }); 当我使用未被注释的list,<div class="xzWxz"> <b><img :src="/BookShopSystem_war/cart/xzwxz.png"></b> </div> 该代码点击后没有变化,而我使用注释的静态list数组,该代码点击有变化,为什么,未注释的list是能获取到数据并遍历了出来,如何解决

时间: 2023-10-11 07:13:16 浏览: 46
根据你提供的代码,点击 `<div class="xzWxz">` 标签后,应该会添加或移除 `on` 类名。但是你说未注释的 `list` 数组使用后没有变化,可能是因为你没有对 `on` 类名进行样式定义,或者在其他地方将其重置了。 至于如何解决,可以先检查一下 `on` 类名是否被正确定义,并且在点击事件后是否被正确地添加或移除。如果问题仍未解决,可以提供更多相关代码和错误信息,以便更好地帮助你解决问题。
相关问题

<!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代码,请结合你给出的分页功能整合出完整的代码

好的,以下是结合分页功能的完整代码: <!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() 方法来渲染分页组件。同时,需要注意在分页回调函数中更新当前显示的数据。

<div class="hot-sell"> <p class="house-title">热销推荐<a href="">更多优品 ></a></p> <div class="layui-row layui-col-space20"> <table> <tr v-for="(hot,index) in hotSellers" :key="index"> <a href="detail.html" class="layui-col-xs3 text"> <div><img src="/BookShopSystem_war/static/img/home_img4.jpg"></div> <p>{{hot.bookId}}</p> <p class="price">¥{{hot.bookPrice}}</p> </a> </tr> </table> </div> </div>该代码控制台报错,显示vue.min.js:6 ReferenceError: hot is not defined,应该如何解决

该错误提示是因为在模板中使用了未定义的变量 hot。可能是因为 hotSellers 数组中没有任何元素导致的。 为了避免这个错误,可以在渲染 hotSellers 数组之前,先进行判断。可以使用 v-if 指令来判断数组是否为空,如果为空,则不进行渲染。 可以将代码修改为如下形式: ``` <div class="hot-sell" v-if="hotSellers.length > 0"> <p class="house-title">热销推荐<a href="">更多优品 ></a></p> <div class="layui-row layui-col-space20"> <table> <tr v-for="(hot,index) in hotSellers" :key="index"> <a href="detail.html" class="layui-col-xs3 text"> <div><img src="/BookShopSystem_war/static/img/home_img4.jpg"></div> <p>{{hot.bookId}}</p> <p class="price">¥{{hot.bookPrice}}</p> </a> </tr> </table> </div> </div> ``` 这样,就可以避免在 hotSellers 数组为空时出现未定义变量的错误了。

相关推荐

0"> {{bk.bookName}} ¥{{bk.bookPrice}} //列表页——分页 layui.use(['laypage'], function () { var laypage = layui.laypage; laypage.render({ elem: 'houseList' , count: 25 , limit: 5 , theme: '#daba91' , layout: ['page', 'next'] }); }); Vue.config.productionTip = false //阻止vue在启动时生成生产提示 new Vue({ el: "#app", data() { return { bookAll: [] } }, mounted() { var _this = this; axios({ method: 'get', url: 'http://localhost:8080/BookShopSystem_war/getBookAll' }).then(function (result) { var code = result.data.code; var data = result.data.data; if (code == 0) { _this.bookAll = data; } console.log(data) }) } })已省略部分代码,数据都可遍历出来,如何实现分页功能

{{ collect.bookName }} ¥{{ collect.bookPrice }} <button @click="delCollect()"> × </button> new Vue({ el: "#app", data: { userId: '', collectBook: [] }, mounted() { var _this = this; axios.get('/BookShopSystem_war/getUserId') .then((response) => { this.userId = response.data; var userId = this.userId; // 将userId赋值给一个变量 axios({ method: 'get', url: 'http://localhost:8080/BookShopSystem_war/getCollectBook/' + userId }).then(function (result) { var code = result.data.code; var data = result.data.data; if (code == 200) { _this.collectBook = data; } console.log(data) }) }) .catch((error) => { console.log(error); }); }, methods: { delCollect() { var _this = this; axios({ method: "delete", url: "http://localhost:8080/BookShopSystem_war/deleteCollect", data: { userId: _this.userId, bookId: _this.collectBook.bookId } }).then(resp => { alert("取消收藏"); }) } }该取消收藏方法有错,给出原因并纠正

这是前端代码 {{ collect.bookName }} ¥{{ collect.bookPrice }} <button @click="delCollect(collect.bookId)"> × </button> new Vue({ el: "#app", data: { userId: '', collectBook: [] }, mounted() { var _this = this; axios.get('/BookShopSystem_war/getUserId') .then((response) => { this.userId = response.data; var userId = this.userId; // 将userId赋值给一个变量 axios({ method: 'get', url: 'http://localhost:8080/BookShopSystem_war/getCollectBook/' + userId }).then(function (result) { var code = result.data.code; var data = result.data.data; if (code == 200) { _this.collectBook = data; } console.log(data) }) }) .catch((error) => { console.log(error); }); }, methods: { delCollect(bookId) { var _this = this; axios({ method: "delete", url: "http://localhost:8080/BookShopSystem_war/deleteCollect", data: { userId: _this.userId, bookId: bookId } }).then(resp => { alert("取消收藏"); // 从 collectBook 数组中移除被删除的收藏 _this.collectBook = _this.collectBook.filter(collect => collect.bookId !== bookId); 请分析逻辑是否有误

#include <iostream>; #include<string>; using namespace std; typedef string ElemType; #define TRUE 1; #define FALSE 0; #define OK 1; #define ERROR 0; #define OVERFLOW -1; #define MAXSIZE 999999; typedef int Status; typedef struct Book { string bookID; //书号 string bookName; //书名 string writerName; //作者 int booknumnow; //现库存量 string biglei; //大类 string smalllei; //小类 }Book, * Bookk; //书本类型 typedef struct LNode //链表 { Book* book; struct LNode* next; }LNode, * LinkList; typedef struct FiveTNode//每一层有五类 { ElemType data; struct FiveTNode* child1, * child2, * child3, * child4, * child5; LNode* lnode; }FiveTNode, * FiveTree; void CreateFiveTree(FiveTree& T, FiveTree& A, FiveTree& B, FiveTree& C, FiveTree& D, FiveTree& E)//创建树 { T = new FiveTNode;//生成根结点 T->data = "图书"; T->child5 = new FiveTNode; FiveTree E = T->child5; E->data = "综合类书籍"; E->child5 = new FiveTNode; E->child5->data = "安全科学"; E->child5->lnode = new LNode; E->child5->lnode->book = new Book; E->child5->lnode->book->bookName = "《安全科学你我需知》"; E->child5->lnode->book->bookID = "25"; E->child5->lnode->book->writerName = "刘俊"; E->child5->lnode->book->booknumnow = 58; E->child5->lnode->next = NULL; //cout << A->child1->lnode->book->bookName; //cout << E->child5->lnode->book->bookID; } int main() { string book_update_ID_new, book_update_ID; cin >> book_update_ID; cin >> book_update_ID_new; FiveTree T, A, B, C, D, E; CreateFiveTree(T, A, B, C, D, E); LinkList s = new LNode; LinkList q, t; LinkList pe5 = E->child5->lnode; s->book->bookID = book_update_ID_new; s->next = pe5->next; pe5->next = s; q = E->child5->lnode; while (q && q->book->bookID != book_update_ID) { q = q->next; } q = q->next; t = q->next; q->next = t->next; delete t; cout << s->book->bookID << " " << s->book->bookName << " " << s->book->writerName << endl; cout << " ***************************************" << endl; return 0; }

最新推荐

recommend-type

麦肯锡-年月―中国xx集团战略咨询项目建议书.ppt

麦肯锡-年月―中国xx集团战略咨询项目建议书.ppt
recommend-type

廖倩5.14运营款.xlsx

廖倩5.14运营款.xlsx
recommend-type

setuptools-25.0.2-py2.py3-none-any.whl

文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这