JavaScript/axios:修订间差异
来自康健生活
| 第36行: | 第36行: | ||
* Content-Type 设置失效 | * Content-Type 设置失效 | ||
*: 请求中如果 data 或者 params 内容为空,即 <code>Content-Length=0</code>,则 Content-Type 无效化(axios 默认不需要这个字段) | *: 请求中如果 data 或者 params 内容为空,即 <code>Content-Length=0</code>,则 Content-Type 无效化(axios 默认不需要这个字段) | ||
* createError.js?2d83:16 Uncaught (in promise) Error: Request aborted | |||
*: 有拼接的数据,所以要用反引号进行编译操作 | |||
* 原代码 | |||
*: <syntaxhighlight lang="javascript"> | |||
asyncData({ params, query, $axios, error }) { | |||
return Promise.all([ | |||
$axios.get('/v2/hospital/search_filters'), | |||
$axios.request({ | |||
url: '/v2/hospital/list', | |||
params: { | |||
country: params.country || '', | |||
dept: params.dept || '', | |||
page: params.page || '1' | |||
} | |||
}) | |||
]).then(([HospitalSearchFilters, HospitalList]) => { | |||
return { | |||
HospitalSearchFilters: HospitalSearchFilters.data || [], | |||
HospitalList: HospitalList.data.list || [] | |||
} | |||
}) | |||
},</syntaxhighlight> | |||