4-7.前端项目-自定义组件
5-2集成HTTP库axios 本节内容 ·
集成HTTP库axios ·完成电子书列表接口前后端交互
1.安装axios,注意版本一致.
npm install axios@0.21.0 --save
setup() {
console.log("setup")
axios.get("http://localhost:8866/ebook/bookresp?name=m").then((response) => {
console.log(response);
})
}
前端请求后端接口获取数据。
报错出现跨域问题,解决办法,在后台添加允许跨域访问代码。
package com.jiawa.wiki.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMap