问题遇到的现象和发生背景
我执行搜索方法,但是代码自动执行获取总数据的方法
问题相关代码,请勿粘贴截图
获取数据方法:
getList(query) {
// 点击分类筛选重置搜索值及分页数
// if(this.modalProps.searchKey!=''){
// this.modalProps.searchKey=''
// }
this.paged=1
const req = new ARequest({
method: 'get',
url: '/api/front/material',
cache: true,
query: {
with:1,
paged:this.paged,
per_page:this.per_page
}
})
req.send().then(res=>{
console.log("关你什么事")
console.log(res)
const pagination = req.pagination()
this.total=pagination.total
let list=[]
res.forEach(val => {
let obj = {
module_id: val.module_id,
imageUrl: val.thumbnail.source_url,
title: val.title
}
list.push(obj)
});
this.list=list
// 判断获取到的数据长度是否等于数据总条数
if(this.list.length>=this.total){
this.contentLoading=false
}else{
this.contentLoading=true
}
// if(this.modalProps.searchKey!=''){
// this.modalProps.searchKey=''
// }
// 缓存当前请求链接
this.cacheUrl=req.options.url
setTimeout(()=>{
this.listLoading = false
},1000)
})
},
搜索方法:
searchClick(value){
// 重置分页数
this.paged=1
// if(this.modalProps.searchKey==''){
// console.log('走你')
// this.getList()
// }else{
this.listLoading = true
const req = new ARequest({
method: 'get',
url: `/api/front/material?search=${value}`,
query: {
with:1,
paged:this.paged,
per_page:this.per_page
}
})
req.send().then(res=>{
const pagination = req.pagination()
this.total=pagination.total
let list=[]
res.forEach(val => {
let obj = {
module_id: val.module_id,
imageUrl: val.thumbnail.source_url,
title: val.title
}
list.push(obj)
});
this.list=list
// 判断获取到的数据长度是否等于数据总条数
if(this.list.length>=this.total){
this.contentLoading=false
}else{
this.contentLoading=true
}
// 缓存当前请求链接
this.cacheUrl=req.options.url
setTimeout(()=>{
this.listLoading = false
},1000)
})
// }
},
运行结果及报错内容
运行搜索方法发送请求,执行后自动运行了getList方法
我想要达到的结果
我只要执行搜索方法内的代码
希望帮助解决一下!!万分感谢