今天在敲代码的时候,遇到了一个
vue-router.mjs:3252 TypeError: Cannot use 'in' operator to search for 'validateStatus' in http://localhost:9090 at mergeDirectKeys (mergeConfig.js:66:14) at computeConfigValue (mergeConfig.js:105:25) at Object.forEach (utils.js:258:10) at mergeConfig (mergeConfig.js:103:53) at Function.create (axios.js:62:91) at eval (request.js:3:1) at ./src/utils/request.js (src_views_testAdmin_vue.js:48:1) at __webpack_require__ (app.js:177:32) at fn (app.js:440:21) at eval (user.js:11:75) vue-router.mjs:60 [Vue Router warn]: Unexpected error when starting the router: TypeError: Cannot use 'in' operator to search for 'validateStatus' in http://localhost:9090 at mergeDirectKeys (mergeConfig.js:66:14) at computeConfigValue (mergeConfig.js:105:25) at Object.forEach (utils.js:258:10) at mergeConfig (mergeConfig.js:103:53) at Function.create (axios.js:62:91) at eval (request.js:3:1) at ./src/utils/request.js (src_views_testAdmin_vue.js:48:1) at __webpack_require__ (app.js:177:32) at fn (app.js:440:21) at eval (user.js:11:75)
中文翻译
vue-router.mjs:3252类型错误:无法使用“in”运算符在http://localhost:9090的merge direct keys(merge config . js:66:14)处的computeConfigValue(merge config . js:105:25)处的object . foreach(utils . js:258:10)处的merge config(merge config . js:103:53)处的function . create 65/src/utils/request . js(src _ views _ test admin _ vue . js:48:1)at _ _ web pack _ require _ _(app . js:177:32)at fn(app . js:440:21)at eval(user . js:11:75) Vue-Router . mjs:60【Vue Router warn】:启动路由器时出现意外错误:类型错误:无法使用“in”运算符搜索http://localhost:9090中的merge direct keys(merge config . js:66:14)处的computeConfigValue(merge config . js:105:25)处的object . foreach(utils . js:258:10)处的merge config(merge config . js:103:53 65/src/utils/request . js(src _ views _ test admin _ vue . js:48:1)at _ _ web pack _ require _ _(app . js:177:32)at fn(app . js:440:21)at eval(user . js:11:75)
怎么解决,参考别人写的文章:
将请求拦截器改成这样就可以了
import axios from "axios"; const baseURL = 'http://localhost:9090'; const instance = axios.create({ baseURL:baseURL }); instance.interceptors.response.use( result => { return result.data; }, err => { alert('服务异常'); return Promise.reject(err); } ) // 导出axios自定义函数 export default instance