AxiosError: Network Error at XMLHttpRequest.handleError (webpack-internal:///./node_modules/axio

简介: AxiosError: Network Error at XMLHttpRequest.handleError (webpack-internal:///./node_modules/axio

今天在写代码配置axios的时候,出现了一个bug

 

Access to XMLHttpRequest at 'http://localhost:9090/videolist' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js:245 
        
        
       GET http://localhost:9090/videolist net::ERR_FAILED 403 (Forbidden)
dispatchXhrRequest @ xhr.js:245
xhr @ xhr.js:57
dispatchRequest @ dispatchRequest.js:53
_request @ Axios.js:155
request @ Axios.js:50
Axios.<computed> @ Axios.js:177
wrap @ bind.js:9
getVideoList @ index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/views/video/videoMainContainer.vue?vue&type=script&lang=js:12
created @ index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/views/video/videoMainContainer.vue?vue&type=script&lang=js:18
callWithErrorHandling @ runtime-core.esm-bundler.js:326
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:334
callHook @ runtime-core.esm-bundler.js:3385
applyOptions @ runtime-core.esm-bundler.js:3310
finishComponentSetup @ runtime-core.esm-bundler.js:6801
setupStatefulComponent @ runtime-core.esm-bundler.js:6728
setupComponent @ runtime-core.esm-bundler.js:6667
mountComponent @ runtime-core.esm-bundler.js:5220
processComponent @ runtime-core.esm-bundler.js:5198
patch @ runtime-core.esm-bundler.js:4873
componentUpdateFn @ runtime-core.esm-bundler.js:5397
run @ reactivity.esm-bundler.js:216
instance.update @ runtime-core.esm-bundler.js:5428
callWithErrorHandling @ runtime-core.esm-bundler.js:326
flushJobs @ runtime-core.esm-bundler.js:516
Promise.then (async)
queueFlush @ runtime-core.esm-bundler.js:432
queuePostFlushCb @ runtime-core.esm-bundler.js:449
queueEffectWithSuspense @ runtime-core.esm-bundler.js:1635
scheduler @ runtime-core.esm-bundler.js:1814
resetScheduling @ reactivity.esm-bundler.js:302
triggerEffects @ reactivity.esm-bundler.js:345
triggerRefValue @ reactivity.esm-bundler.js:1020
set value @ reactivity.esm-bundler.js:1061
finalizeNavigation @ vue-router.mjs:3146
eval @ vue-router.mjs:3028
Promise.then (async)
pushWithRedirect @ vue-router.mjs:2999
push @ vue-router.mjs:2925
handleMenuItemClick @ menu.mjs:178
handleClick @ menu-item2.mjs:51
onClick._cache.<computed>._cache.<computed> @ menu-item2.mjs:83
callWithErrorHandling @ runtime-core.esm-bundler.js:326
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:334
invoker @ runtime-dom.esm-bundler.js:841
Show 42 more frames
Show less
home:1 Uncaught (in promise) AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}

意思:

CORS策略已阻止从源“http://localhost:8080”访问位于“http://localhost:9090/video list”的XMLHttpRequest:请求的资源上不存在“Access-Control-Allow-Origin”标头。
xhr.js:245
<template>
  <div>
    <el-carousel :interval="4000" type="card" height="200px">
    <el-carousel-item v-for="item in 6" :key="item">
      <h3  class="medium">{{ item }}</h3>
    </el-carousel-item>
  </el-carousel>
  </div>
</template>
 
<script>
import axios from "axios";
export default {
  data(){
    return {
      videoList:[]
    }
  },
  methods:{
    getVideoList(){
      axios.get("/videolist").then((res)=>{
        console.log(res);
      })
    }
  },
  created(){
    this.getVideoList();
  }
}
</script>
 
<style>
 
</style>

这里经过查找,找到出错的bug,自己util的跨域路径是8081

而自己跑的项目是8080

路径设置不一致,因此出错了,修改一样就好了

自己webConfig的配置:

package zero.file.videoProject.util;
 
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
           registry.addMapping("/**")
                        .allowedOrigins("http://localhost:8080")
                        .allowedMethods("GET","POST","PUT","OPTIONS","DELETE")
                        .allowCredentials(true)
                        .maxAge(3600);
            }
}

WebConfig要在util下配置


相关文章
|
6月前
webpack 使用打包报错 ERROR in node_modules\@types\node\ts4.8\assert.d.ts
webpack 使用打包报错 ERROR in node_modules\@types\node\ts4.8\assert.d.ts
416 0
|
3月前
Node——activeError: error:0308010C:digital envelope routines::unsupported
启动项目报错error:0308010C:digital envelope routines::unsupported,其实很简单因为node版本的原因,本地默认的版本是v20.15.0,项目是老项目默认的版本是v16.16.0;
106 2
|
6月前
|
Shell
Flume【问题记录 01】【at org.apache.flume.node.Application.main(Application.java:xxx) 类问题整理+其他类型问题总结】【避坑指南】
【2月更文挑战第17天】Flume【问题记录 01】【at org.apache.flume.node.Application.main(Application.java:xxx) 类问题整理+其他类型问题总结】【避坑指南】
308 2
|
3月前
Mac 安装 Node Error: Could not symlink include/node/common.gypi
Mac 安装 Node Error: Could not symlink include/node/common.gypi
31 3
|
3月前
error in ./node_modules/@intlify/core-base/dist/core-base.cjs
error in ./node_modules/@intlify/core-base/dist/core-base.cjs
92 2
|
4月前
|
JavaScript Windows
安装node.js与webpack创建vue2项目
安装node.js与webpack创建vue2项目
35 1
|
3月前
|
JavaScript Linux Windows
【应用服务 App Service】NodeJS +Egg 发布到App Service时遇见 [ERR_SYSTEM_ERROR]: A system error occurred:uv_os_get_passwd returned ENOENT(no such file or directory)
【应用服务 App Service】NodeJS +Egg 发布到App Service时遇见 [ERR_SYSTEM_ERROR]: A system error occurred:uv_os_get_passwd returned ENOENT(no such file or directory)
|
3月前
|
JavaScript 前端开发
NodeJs——error:03000086:digital envelope routines::initialization error
NodeJs——error:03000086:digital envelope routines::initialization error
65 0
|
3月前
|
JavaScript
NodeJs——Parsing error: Cannot read file '.../tsconfig.json'.eslint
NodeJs——Parsing error: Cannot read file '.../tsconfig.json'.eslint
34 0
|
3月前
|
缓存 资源调度 JavaScript
Nodejs 命令行调用 exec 与 spawn 差异--- 解决 spawn yarn ENOENT error
Nodejs 命令行调用 exec 与 spawn 差异--- 解决 spawn yarn ENOENT error