1、在vue项目文件中安装axios npm i axios
2、在vue.config.js中写
devServer: {
port:5700, // 端口名
open:true, // 自动打开浏览器
hot:true, // 热模块替换
proxy: { // 代理
'/mt': { // 接口名称 可定义
target: 'http://ustbhuangyi.com', // 写跨域的网址
pathRewrite: { '^/mt': '' },
changeOrigin: true // 是否跨域
}
}
}
示例:
3、在vue页面中引入axios import axios from "axios";
4、在export default 中写created
created() {
axios.get("/mt/sell/api/seller").then((res) => {
this.info = res.data.data;
});
}
示例: