vue 開發/生產環境配置

生產環境跨域
dev: {
  assetsSubDirectory: 'static', //靜態資源根目錄的子目錄static,也就是dist目錄下面的static
  assetsPublicPath: '/', //編譯發佈的根目錄,可配置爲資源服務器域名或 CDN 域名
  proxyTable: {}, //proxyTable 代理的接口(可跨域)
  host: 'localhost',
  port: 8080, //dev-server的端口號,可以自行更改
  autoOpenBrowser: false, //是否自動打開瀏覽器
  errorOverlay: true,
  notifyOnErrors: true,
  poll: false,
  useEslint: true,
  showEslintErrorsInOverlay: false,
  devtool: 'cheap-module-eval-source-map',
  cacheBusting: true,
  cssSourceMap: true //默認情況下,關閉 CSS Sourcemaps,因爲使用相對路徑會報錯
 },  

 

proxyTable: {
 '/cms': { //代理地址
  target: 'http://192.168.0.112:8080', //需要代理的地址
  changeOrigin: true, //是否跨域
  secure: false,
  pathRewrite: {
   '^/cms': '/cms' //本身的接口地址沒有'/cms' 這種通用前綴,所以要rewrite,如果本身有則去掉(/cms等價於 www.xxx.com/cms)
  }
 }
},

 

this.$axios.get('/cms/queryMaterial', {params: params})
  .then((res) => {
  console.log(res);
}).catch((err) => {
  console.log(err);
})

 

proxyTable: {
 '/list': {
  target: 'http://www.xxx.com',
  pathRewrite: {
   '^/list': '/list'
  }
 }
}

 

proxyTable: {
 '/list': {
  target: 'http://www.xxx.com',
  changeOrigin: true,
  pathRewrite: {
   '^/list': '/list'
  }
 }
}

 

'use strict'
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')

module.exports = merge(prodEnv, {
 NODE_ENV: '"development"'
})

 

'use strict'
const merge = require('webpack-merge')
const prodEnv = require('./prod.env')

module.exports = merge(prodEnv, {
 NODE_ENV: '"development"',
 API_ROOT: '"//192.168.0.112:8080"'
})

 

'use strict'
module.exports = {
 NODE_ENV: '"production"'
}

 

'use strict'
module.exports = {
 NODE_ENV: '"production"',
 API_ROOT: '"//www.baidu.com/api"'
}

 

main.js裏面

Vue.prototype.$axios = Axios

Axios.defaults.baseURL = process.env.API_ROOT

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章