1.在最大的文件夹下面建一个vue.config.js
2.在vue.config.js
module.exports = {
devServer: {
proxy: {
'': {
target: "http://xxx.xxx.x.xxx:8208", //接口地址
changeOrigin: true,
pathRewrite: {}
}
}
}
}
3.在main.js里面写
import axios from 'axios'
Vue.prototype.$axios = axios
4.然后在login.vue里面用这个接口
methods: {
loginIn() {
this.$refs.loginFromRef.validate( async (valid) =>{
if (!valid) return;
const res = await this.$axios.post('/login', this.loginform)
console.log(res);
})
// this.$router.push("/Home");
},
},