不負(fù)相思意
2018-11-29 14:10:14
在vue的methods,函數(shù)search作用是返回請求數(shù)據(jù),但是報(bào)錯(cuò)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); })},但是不明白如何調(diào)用這個(gè)search,獲取到data??嘗試下面的方法,報(bào)錯(cuò),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貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超8個(gè)贊
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;
添加回答
舉報(bào)
0/150
提交
取消