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]; } }); },
时间: 2023-12-06 12:42:58 浏览: 33
这是一个 Vue.js 的方法,用于获取旅游景点的列表数据。它接受三个参数,分别是页码、分类和 ref(默认为空字符串)。首先它会判断分类是否为“全部”,如果是则把 swiperIndex(轮播图的索引)设置为-1,否则遍历分类数组找到对应的分类并将 swiperIndex 设置为对应的索引值。然后将当前分类赋值给 curFenlei 变量,并根据 curFenlei 是否为“全部”来决定是否设置 isPlain 变量为 false 或 true。接下来根据传入的参数组装成查询条件 searchWhere,然后通过 HTTP GET 请求获取数据,并将获取到的数据赋值给 dataList、total、pageSize 和 totalPage 等变量。最后根据 pageSize 计算出 pageSizes 数组,并返回获取到的数据。
相关问题
getList(page, fenlei, ref = '') { if(fenlei == '全部') this.swiperIndex = -1; for(let i=0;i<this.fenlei.length;i++) { if(fenlei == this.fenlei[i]) { this.swiperIndex = i; break; } } this.curFenlei = fenlei; if (this.curFenlei == '全部') { this.isPlain = false; } else { this.isPlain = true; }
这段代码看起来是一个Vue组件中的方法,其中的参数page表示页数,fenlei表示分类,ref表示参考信息。首先判断分类是否为“全部”,如果是则把swiperIndex设置为-1,否则遍历分类数组this.fenlei并找到对应的分类,把swiperIndex设置为对应的索引值。然后将当前分类赋值给curFenlei变量,并根据curFenlei是否为“全部”来决定是否设置isPlain变量为false或true。
fetchData() { // this.list = [] this.listLoading = true this.good.pageSize = this.pageSize this.good.pageIndex = this.currentPage4 console.log(this.good.uintPirce) if (this.good.uintPirce === '' || this.good.uintPirce === null) { this.good.uintPirce = 0 } getList(this.good).then(response => { this.list = response.data.records this.total = response.data.total this.pageSize = response.data.size // this.total = response.data.pages this.currentPage4 = response.data.current this.listLoading = false }) },解释以上每一行代码
以下是对您提供的代码片段的逐行解释:
1. `this.listLoading = true`: 将 `listLoading` 属性设置为 `true`,用于显示加载状态。
2. `this.good.pageSize = this.pageSize`: 将 `good` 对象的 `pageSize` 属性设置为当前的 `pageSize` 值。
3. `this.good.pageIndex = this.currentPage4`: 将 `good` 对象的 `pageIndex` 属性设置为当前的 `currentPage4` 值。
4. `console.log(this.good.uintPirce)`: 打印出 `good` 对象的 `uintPirce` 属性的值,用于调试目的。
5. `if (this.good.uintPirce === '' || this.good.uintPirce === null) { ... }`: 如果 `good` 对象的 `uintPirce` 属性为空字符串或者为 `null`,则执行下面的逻辑。
6. `this.good.uintPirce = 0`: 将 `good` 对象的 `uintPirce` 属性设置为 0。
7. `getList(this.good).then(response => { ... })`: 调用一个名为 `getList` 的函数,并将 `good` 对象作为参数传递给它。这个函数可能是获取列表数据的后端接口。
8. `.then(response => { ... })`: 如果获取列表数据成功,则执行回调函数,并将返回的响应作为参数传递给它。
9. `this.list = response.data.records`: 将返回的响应中的 `records` 属性赋值给 `list` 数组,用于显示列表数据。
10. `this.total = response.data.total`: 将返回的响应中的 `total` 属性赋值给 `total` 变量,用于显示总记录数。
11. `this.pageSize = response.data.size`: 将返回的响应中的 `size` 属性赋值给 `pageSize` 变量,用于显示每页记录数。
12. `this.currentPage4 = response.data.current`: 将返回的响应中的 `current` 属性赋值给 `currentPage4` 变量,用于显示当前页码。
13. `this.listLoading = false`: 将 `listLoading` 属性设置为 `false`,用于隐藏加载状态。
希望以上解释能对您有所帮助。如果您还有其他问题,请随时提问!