zoukankan      html  css  js  c++  java
  • vue.js 本地解决跨域

    1、config/index.js下添加proxyTable

    dev: {
        // Paths
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        proxyTable:{
          "/api/*":{
            target: 'http://*.*.*.*:9502',//后端接口地址
            secure:false,
            changeOrigin:true,
            pathRewrite:{
              "^/api":""
            }
          }
        },
    
        // Various Dev Server settings
    
        // can be overwritten by process.env.HOST
        // if you want dev by ip, please set host: '0.0.0.0'
        host: '192.168.1.127',
        port: 9527, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
        autoOpenBrowser: true,
    }
    

      2、配置config/dev.env.js  (本地地址+api)

    module.exports = {
      NODE_ENV: '"development"',
      ENV_CONFIG: '"dev"',
     // BASE_API: '"http://172.17.92.255:9502"'
      BASE_API: '"http://192.168.1.127:9527/api"'
    }
    

      3、创建request.js请求接口

    // create an axios instance
    const service = axios.create({
      baseURL: process.env.BASE_API, // api 的 base_url
      timeout: 5000,// request timeout,
      headers: {
        'Content-Type': 'application/json; charset=utf-8'
      }
    })
    

      4、实例

    export function getContractList(data = {}, headData={}) {
      return request({
        url: '/cms/companyList',
        method: 'post',
        data: data,
        headers:headData
      })
    }
    

      

  • 相关阅读:
    Zookeeper简介
    ArrayList
    Java数据类型的零碎知识
    Cookie/Session/Token对比
    布隆过滤器(Bloom Filter)
    Spring MVC简介
    Spring简介
    win10系统64位安装git后右键运行git bash here生成一个mintty.exe.stackdump文件后闪退解决方案
    CSS属性速查表
    Sublime text3中配置Github
  • 原文地址:https://www.cnblogs.com/lvxj-litchi/p/12059967.html
Copyright © 2011-2022 走看看