在vue的methods,函数search作用是返回请求数据,但是报错search(options) { const url = this.isTeacher? '/api/search_Teacher' : '/apis/org/search_student'; const params = options.ids ? { ids: options.ids } : { keyword: this.keyword }; return this.$http.get(url, { params }).then((response) => { return response.body; }, (err) =>{ console.log(err); })},但是不明白如何调用这个search,获取到data??尝试下面的方法,报错,this.search is not a function?? this.seach({ ids: this.selected }).then((res) => { if (!res) this.$message.error('搜索失败'); else this.selectedData = res; });有没有好的方法,谢谢
1 回答
www说
TA贡献1775条经验 获得超8个赞
async search(options) {
const url = this.isTeacher? '/api/search_Teacher' : '/apis/org/search_student';
const params = options.ids ? { ids: options.ids } : { keyword: this.keyword };
try {
const res = await this.$http.get(url, { params })
return res.body
} catch (e) {
console.log(e)
}
},
use
const data = await this.search({ ids: this.selected })
if (!data) this.$message.error('搜索失败');
else this.selectedData = data;
添加回答
举报
0/150
提交
取消