zoukankan      html  css  js  c++  java
  • vue 跨域问题解决办法

    1、打开config-index.js配置

    proxyTable: {
          '/api': {
              target: 'https://bmpapi.bigoffs.cn', //你要跨域的网址  比如  'http://news.baidu.com',
              secure: true, // 如果是https接口,需要配置这个参数
              changeOrigin: true, //这个参数是用来回避跨站问题的,配置完之后发请求时会自动修改http header里面的host,但是不会修改别的
              pathRewrite: {
                  '^/api': '' //路径的替换规则
                      //这里的配置是正则表达式,以/api开头的将会被用用‘/api’替换掉,假如后台文档的接口是 /api/list/xxx
                      //前端api接口写:axios.get('/api/list/xxx') , 被处理之后实际访问的是:http://news.baidu.com/api/list/xxx
              }
          }
      },

    2、再main.js中

    Vue.prototype.HOST = '/api'

    3、引用的地方

    var url = this.HOST+'/viewsetup/viewcontent/viewcontent?channel=offsshop' 
    this.$axios.get(url)
       .then(data => {
            console.log(data)
       }).catch(err =>{
            console.error(err.response);
       })
    proxyTable: {
          '/api': {
              target: 'https://bmpapi.bigoffs.cn'//你要跨域的网址  比如  'http://news.baidu.com',
              secure: true// 如果是https接口,需要配置这个参数
              changeOrigin: true//这个参数是用来回避跨站问题的,配置完之后发请求时会自动修改http header里面的host,但是不会修改别的
              pathRewrite: {
                  '^/api': '' //路径的替换规则
                      //这里的配置是正则表达式,以/api开头的将会被用用‘/api’替换掉,假如后台文档的接口是 /api/list/xxx
                      //前端api接口写:axios.get('/api/list/xxx') , 被处理之后实际访问的是:http://news.baidu.com/api/list/xxx
              }
          }
      },
  • 相关阅读:
    某些输入文件使用或覆盖了已过时的 API
    laravel 重写以及500错误
    Ubuntu镜像使用帮助
    E: Sub-process /usr/bin/dpkg returned an error code (1) 解决方案
    python请求java Selenium Webdriver
    Selenium Grid 简易安装
    selenium + python 添加等待时间
    selenium帮助手册以及 webdriver的各种driver
    thinkphp结合layui上传图片
    thinkphp----替换写标签的方法
  • 原文地址:https://www.cnblogs.com/yaoling/p/14051910.html
Copyright © 2011-2022 走看看