我們?cè)赩ue實(shí)現(xiàn)axios請(qǐng)求時(shí),出現(xiàn)跨域問題,我們有兩種解決方案(當(dāng)然我們的請(qǐng)求路徑和axios都是沒問題的)
?
methods: {
aaa: function () {
axios({
url: 'http://localhost:8081/chd',
method: 'post',
data: {
account: this.account,
password: this.password
}
}).then(response => {
console.log('@', response);
if(response.data==='OK'){
this.$router.push("/home")
}
})
}
}
?第一種加上CrossOrigin注解
第二種寫一個(gè)config配置類
文章來源:http://www.zghlxwxcb.cn/news/detail-526191.html
@Configuration
public class CustConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("*")
.allowedHeaders("*")
.allowedOrigins("*");
}
}
希望能幫到各位,文章來源地址http://www.zghlxwxcb.cn/news/detail-526191.html
到了這里,關(guān)于axios請(qǐng)求解決跨域問題has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ header is的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!