vue cli3配置端口和设置跨域,用axios post请求传参

1,话不多说,直接代码

根目录创建vue.config.js

module.exports = {
    devServer: {
      port: 3000, // 端口
      proxy: {
        '/api': {
            target: 'http://192.168.9.217:8999/',
            changeOrigin: true,
            ws: true,
            pathRewrite: {
              '^/api': ''
            }
        }
    }
    },
    // lintOnSave: false // 取消 eslint 验证
  }
View Code

axios post传参问题

methods:{
      getParent(){
          console.log(this.input);
         
          const params = new URLSearchParams();
          params.append('name', this.input);
          params.append('password', this.input1);
          this.$axios.post('api/user/login',params)
            .then(function (response) {
                console.log(response);
            })
            .catch(function (error) {
                console.log(error);
            });
      }
 },
View Code

关于axios post请求传参问题详情

猜你喜欢

转载自www.cnblogs.com/xqhv587/p/11968514.html