zheye-master源码 下载安装运行报错

来源:6-6 vue-router 添加路由

weixin_慕莱坞6472890

2021-06-24

下载zheye-master源码,
axios.defaults.baseURL = 'http://apis.imooc.com/api/'
axios.interceptors.response.use(config => {
setTimeout(() => {
store.commit(‘setLoading’, false)
}, 1000)
config.params = { …config.params, icode: ‘E7E6B7151E99C72E’ }
if (config.data instanceof FormData) {
config.data.append(‘icode’, ‘E7E6B7151E99C72E’)
} else {
// 普通的 body 对象,添加到 data 中
config.data = { …config.data, icode: ‘E7E6B7151E99C72E’ }
}
return config
}, e => {
const { error } = e.response.data
store.commit(‘setError’, { status: true, message: error })
store.commit(‘setLoading’, false)
return Promise.reject(e.response.data)
})
下载并运行后报错
✖ 1 problem (1 error, 0 warnings)
1 error and 0 warnings potentially fixable with the --fix option.

@ multi (webpack)-dev-server/client?http://192.168.0.161:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts

Type checking in progress…
ERROR in D:/学习/typescript/新建文件夹/zheye-master/zheye/src/main.ts(17,12):
17:12 Property ‘params’ does not exist on type ‘AxiosResponse’.
15 | store.commit(‘setLoading’, false)
16 | }, 1000)

17 | config.params = { …config.params, icode: ‘E7E6B7151E99C72E’ }
| ^
18 | if (config.data instanceof FormData) {
19 | config.data.append(‘icode’, ‘E7E6B7151E99C72E’)
20 | } else {
ERROR in D:/学习/typescript/新建文件夹/zheye-master/zheye/src/main.ts(17,33):
17:33 Property ‘params’ does not exist on type ‘AxiosResponse’.
15 | store.commit(‘setLoading’, false)
16 | }, 1000)
17 | config.params = { …config.params, icode: ‘E7E6B7151E99C72E’ }
| ^
18 | if (config.data instanceof FormData) {
19 | config.data.append(‘icode’, ‘E7E6B7151E99C72E’)
20 | } else {

写回答

1回答

张轩

2021-06-25

同学你好 这些设置 icode 的代码应该是添加到 请求的拦截器当中:

也就是 axios.interceptors.request

而你写在了 axios.interceptors.response 中


0
1
weixin_慕莱坞6472890
非常感谢!
2021-06-30
共1条回复

Vue3 + TS 仿知乎专栏企业级项目

带你完成前后端分离复杂项目,率先掌握 vue3 造轮子技能

3195 学习 · 2362 问题

查看课程