【 Vue 】配置跨域

配置跨域

vue.config.js

module.exports = {// 配置跨域devServer: {proxy: {'/api': {// 接口路径target: 'http://localhost:5050/',// 是否跨域changeOrigin: true,ws: true,pathRewrite: {'^/api': ''  //路径重写 }}}}
}

获取数据

<script>
export default {name: "Login",data() {return {userInfo: {name: "zwj",email: "2236541780@qq.com",role: "user",password: "123456",},};},methods: {getData() {this.$axios.post("/api/user/register", this.userInfo).then((res) => {console.log(res);}).catch((error) => {console.log(error);});},},created() {this.getData();},
};
</script>

在这里插入图片描述
在这里插入图片描述