get_comment(obj, page = 1, size = 5) { this.$get( "~/api/comment/get_list?", { source_table: "dish_information", source_field: "dish_information_id", source_id: this.obj["dish_information_id"], page, size, reply_to_id: "0", orderby: "create_time desc", }, (json) => { if (json.result) { var list_comment = json.result.list; list_comment.map((o) => { o.list_reply = []; }); this.add_reply(list_comment).then((list) => { this.list_comment = list; }); this.count_pages = Math.ceil(json.result.count / size) || 1 } } ); },
时间: 2023-12-06 09:42:26 浏览: 36
这是一个使用 Vue.js 框架编写的前端函数,主要是用于获取评论列表。它通过调用一个接口来获取评论数据,接口地址为 "~/api/comment/get_list?",并且传递了一些参数,例如评论来源表、来源字段、来源 ID、页码、每页大小等等。获取到评论数据后,它会对每条评论的回复列表进行初始化,并将整个评论列表存储在组件的 list_comment 变量中。同时,它还计算出了总页数,并将结果存储在组件的 count_pages 变量中。
相关问题
change_praise(obj) { var user_id = this.user.user_id; var query = { source_table: "dish_information", source_field: "dish_information_id", source_id: this.obj["dish_information_id"], user_id }; var _this = this; _this.obj.praise_len = parseInt(_this.obj.praise_len) // 点赞状态 if (this.state_praise) { this.state_praise = false; this.$get('~/api/praise/del?', query, (res) => { if(res.result){ var praise_len = _this.obj.praise_len-1 this.$post('~/api/dish_information/set?dish_information_id=' + _this.obj["dish_information_id"], { praise_len }, (res) => { if(res.result){ console.log("添加点赞数状态:" ,res.result); } else if(res.error){ console.error(res.error); } }); this.$toast("取消点赞"); } else if (res.error){ this.$toast(res.error.message); console.error(res.error); } }); } else { this.state_praise = true; this.$post('~/api/praise/add?', query, (res) => { if (res.result) { var praise_len = _this.obj.praise_len+1 this.$post('~/api/dish_information/set?dish_information_id=' + _this.obj["dish_information_id"], { praise_len }, (res) => { if(res.result){ console.log("添加点赞数状态:" ,res.result); } else if(res.error){ console.error(res.error); } }); this.$toast("点赞成功"); } else if (res.error) { this.$toast(res.error.message); console.error(res.error); } }); }; },
这是一个 Vue.js 中的方法,用于处理点赞操作。当用户点击点赞按钮时,会调用该方法。它会根据当前点赞状态来决定是添加点赞还是取消点赞,并相应地更新点赞数和状态。具体实现过程中,它会向服务器发送请求来添加或删除点赞,并通过回调函数来处理服务器返回的结果。其中,obj 是一个包含菜品信息的对象,state_praise 是一个布尔值,表示当前的点赞状态。
get_praise(obj) { var user_id = this.user.user_id; this.$get("~/api/praise/count?", { source_table: "dish_information", source_field: "dish_information_id", source_id: obj["dish_information_id"] }, (res) => { if (res.result || res.result === 0) { this.praise = res.result; console.log("点赞数:" ,res.result); } else if (res.error){ this.$toast(res.error.message); console.error(res.error); } }); this.$get("~/api/praise/count?", { source_table: "dish_information", source_field: "dish_information_id", source_id: obj["dish_information_id"], user_id }, (res) => { if (res.result || res.result === 0) { this.state_praise = res.result ? true : false; console.log("点赞状态:" ,res.result); } else if (res.error){ this.$toast(res.error.message); console.error(res.error); } }) },
这段代码是一个 Vue.js 组件中的一个方法,用于获取某个菜品信息的点赞数和当前用户是否点过赞。具体来说,该方法会向服务器发送两个 GET 请求,分别获取菜品信息的点赞数和当前用户是否已点赞。其中,`obj` 是包含菜品信息的对象,`this.user.user_id` 是当前用户的 ID。
第一个 GET 请求会向 `~/api/praise/count?` 发送请求,参数包括 `source_table`(来源表格,这里是 "dish_information")、`source_field`(来源字段,这里是 "dish_information_id")和 `source_id`(来源 ID,这里是 `obj["dish_information_id"]`),用于获取菜品信息的点赞数。如果请求成功,返回的结果会保存在 `this.praise` 中,表示点赞数。如果请求失败,会通过 `$toast` 方法弹出错误信息。
第二个 GET 请求同样向 `~/api/praise/count?` 发送请求,参数包括 `source_table`、`source_field`、`source_id` 和 `user_id`(用户 ID,这里是 `this.user.user_id`),用于获取当前用户是否已经点过赞。如果请求成功,返回的结果会保存在 `this.state_praise` 中,表示当前用户是否已经点过赞。如果请求失败,同样会通过 `$toast` 方法弹出错误信息。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)