Web前端之路让前端飞技术干货

Vue 开发模式下跨域问题

2017-06-05  本文已影响392人  45b645c5912e
import axios from 'axios'
import config from '../config'
export default {
  request (method, uri, data, headerConfig = {withCredentials: true}) {
    if (!method) {
      console.error('API function call requires method argument')
      return
    }

    if (!uri) {
      console.error('API function call requires uri argument')
      return
    }

    let url = config.serverURI + uri

    return axios({ method, url, data, ...headerConfig })
  }
}
$.ajax({
    type: "POST",
    url: "http://www.xxx.com/api.php",
    dataType: 'json',
    xhrFields: {
        withCredentials: true
    },
    crossDomain: true
}).then((json) => {
    // balabala...
})
var path = require('path')
module.exports = {
  build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../xxx/index.html'),
    assetsRoot: path.resolve(__dirname, '../xxx'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    productionSourceMap: true,
    productionGzip: false,
    productionGzipExtensions: ['js', 'css']
  },
  dev: {
    env: require('./dev.env'),
    port: 8080,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/api': {
        target: 'http://www.xxx.com/api.php/',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/'
        }
      }
    },
    cssSourceMap: false
  }
}
上一篇 下一篇

猜你喜欢

热点阅读