vue cross-domain problem solving (production)

vue cross-domain problem solving (using webpack packaged)

  • Configuration Agent: (config file under index.js)

    module.exports = {
      dev: {
        env: require('./dev.env'),
        autoOpenBrowser: true,
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        //在dev中添加下面的块
        proxyTable: {
          '/api': {
            // target: 'http://47.100.34.99',  //目标接口域名
            target: 'http://10.230.152.141:8080/',
            changeOrigin: true,  //是否跨域
            secure: false,
            pathRewrite: {
              '^/api': ''   //重写接口
            }
          },
          cssSourceMap: false
        },
    ...
    }
  • use

    this.$axios.post("/api/greeting", {
    
                  username: self.name,
                  password: self.password,
                  email: self.email,
                  sex: self.select
              })
              .then(function(res) {
                alert(res.data+",,,,success")
              })
              .catch(function(error) {
              }

Note: currently only tested in a production environment, you can cross-domain

Reference Hirofumi: Https://Blog.Csdn.Net/u012369271/article/details/72848102

Guess you like

Origin www.cnblogs.com/qujialin/p/10975258.html