getHotList() { let autoSortUrl = ""; autoSortUrl = "lvyoujingdian/autoSort"; this.$http.get(autoSortUrl, {params: { page: 1, limit: 4, }}).then(res => { if (res.data.code == 0) { this.hotList = res.data.data.list; } }) },
时间: 2023-12-06 15:43:11 浏览: 25
这段代码是一个 Vue.js 的方法,用于从服务器获取数据并更新组件中的数据。具体来说,它使用了 Vue.js 中的 $http 方法向服务器发送 GET 请求,请求地址为 "lvyoujingdian/autoSort",并且带有两个参数:page 和 limit。服务器返回的数据将通过 then 方法中的回调函数进行处理。如果返回的数据 code 属性为 0,则将数据中的列表 list 赋值给组件中的 hotList 属性。整个过程实现了异步请求数据并更新组件的功能。
相关问题
if (type == -1 && this.isStoreup) {//取消收藏 this.$http.get('storeup/list', { params: { page: 1, limit: 1, type: 1, refid: this.detail.id, tablename: 'lvyoujingdian', userid: localStorage.getItem('userid') } }).then(res => { if (res.data.code == 0 && res.data.data.list.length > 0) { this.isStoreup = true; this.storeupInfo = res.data.data.list[0]; let delIds = new Array(); delIds.push(this.storeupInfo.id); this.$http.post('storeup/delete', delIds).then(res => { if (res.data.code == 0) { this.isStoreup = false; this.$message({ type: 'success', message: '取消成功!', duration: 1500, }); } }); } });
这是一段 Vue.js 的代码,用于取消收藏操作。首先判断 `type` 是否为 -1 并且 `isStoreup` 为 `true`,如果是,则向服务器发送 GET 请求,获取收藏列表中与当前详情页关联的收藏记录。如果获取到了数据,将 `isStoreup` 设为 `true`,并将收藏信息存储到 `storeupInfo` 中。接着构造一个数组 `delIds`,将当前收藏记录的 ID 添加到其中,并向服务器发送 POST 请求执行删除操作。如果删除成功,则将 `isStoreup` 设为 `false`,并显示一个成功的提示消息。
getList(page, fenlei, ref = '') { if(fenlei == '全部') //首先判断分类是否为“全部” this.swiperIndex = -1;//如果是则把swiperIndex设置为-1 for(let i=0;i<this.fenlei.length;i++) {//遍历分类数组this.fenlei,找到对应的分类 if(fenlei == this.fenlei[i]) { this.swiperIndex = i;//把swiperIndex设置为对应的索引值 break; } } this.curFenlei = fenlei;//将当前分类赋值给curFenlei(当前分类)变量 if (this.curFenlei == '全部') {//根据curFenlei是否为“全部”来决定是否设置isPlain变量为false或true this.isPlain = false; } else { this.isPlain = true; } let params = {page, limit: this.pageSize}; let searchWhere = {}; if (this.formSearch.jingdianmingcheng != '') searchWhere.jingdianmingcheng = '%' + this.formSearch.jingdianmingcheng + '%'; if (this.formSearch.jingdiandizhi != '') searchWhere.jingdiandizhi = '%' + this.formSearch.jingdiandizhi + '%'; if(this.formSearch.menpiaojiagestart!='' && this.formSearch.menpiaojiagestart!=undefined ){ searchWhere.menpiaojiagestart = this.formSearch.menpiaojiagestart } if(this.formSearch.menpiaojiageend!='' && this.formSearch.menpiaojiageend!=undefined){ searchWhere.menpiaojiageend = this.formSearch.menpiaojiageend } if (this.curFenlei != '全部') searchWhere.jingdianleixing = this.curFenlei; this.$http.get('lvyoujingdian/list', {params: Object.assign(params, searchWhere)}).then(res => { if (res.data.code == 0) { this.dataList = res.data.data.list; this.total = res.data.data.total; this.pageSize = res.data.data.pageSize; this.totalPage = res.data.data.totalPage; this.pageSizes = [this.pageSize, this.pageSize*2, this.pageSize*3, this.pageSize*5]; } }); },
这是一个 Vue.js 的方法,用于获取旅游景点的列表数据。它接受三个参数,分别是页码、分类和 ref(默认为空字符串)。首先它会判断分类是否为“全部”,如果是则把 swiperIndex(轮播图的索引)设置为-1,否则遍历分类数组找到对应的分类并将 swiperIndex 设置为对应的索引值。然后将当前分类赋值给 curFenlei 变量,并根据 curFenlei 是否为“全部”来决定是否设置 isPlain 变量为 false 或 true。接下来根据传入的参数组装成查询条件 searchWhere,然后通过 HTTP GET 请求获取数据,并将获取到的数据赋值给 dataList、total、pageSize 和 totalPage 等变量。最后根据 pageSize 计算出 pageSizes 数组,并返回获取到的数据。
相关推荐
![](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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)