axios请求到了数据但then返回不到数据,这是由于vue前端访问地址出现的跨域问题。
1、如果你是自己写的后端,可以添加配置类来避免跨域问题(建议使用)
package com.ftest.springboot.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class CrosConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("*") .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") .allowCredentials(true) .allowedHeaders("*") .maxAge(3600); } }
这样就不用担心跨域了!
- Error createError Uncaught Network promiseerror createerror uncaught network elementui uncaught promise cancel network error axios catch createerror uncaught properties typeerror undefined uncaught syntaxerror unexpected uncaught页面 addeventlistener typeerror uncaught property referenceerror uncaught defined bobj typeerror undefined uncaught property