【发布时间】:2022-01-15 18:31:55
【问题描述】:
我正在尝试在我的应用程序中使用 vue-select 包。我有一些从文档中复制的代码,它工作正常。但是,为了便于阅读,我想将其转换为使用 axios 而不是 fetch(),这样我也可以使用自己的 axios 配置设置。
如何将以下代码转换为使用 axios 而不是 fetch?
search: debounce((loading, search, vm) => {
fetch(
`https://api.github.com/search/repositories?q=${escape(search)}`
).then((res) => {
res.json().then((json) => (vm.options = json.items))
loading(false)
})
}, 350)
我尝试了以下代码,但出现错误:Uncaught (in promise) TypeError: res is not a function:
search: debounce(async (loading, search, vm) => {
await axios
.get(`https://api.github.com/search/repositories?q=${escape(search)}`)
.then((res) => {
res((json) => (vm.options = json.items))
loading(false)
})
}, 350)
【问题讨论】:
标签: vuejs2 axios vue-select