• vue 跨域使用


    1. vue.config.js 文件中添加如下代码

    module.exports = {
      devServer: { 
        proxy: {
          "/api": {
            target"http://localhost:3000"//你要跨域的网址  比如  'http://news.baidu.com',
            // secure: true, // 如果是https接口,需要配置这个参数
            changeOrigintrue//这个参数是用来回避跨站问题的,配置完之后发请求时会自动修改http header里面的host,但是不会修改别的
          }
        },
      }
    }
     
     
     

    页面使用:

        axios({
          method'get',
          url'/api/user'  //url 不能是全路径 如果全局封装则baseurl设置"/
        }).then((res=> {
          console.log(res);
        }).catch((error=> {
          console.log(error);
        })
  • 相关阅读:
    获取ip地址,
    手机div侧滑删除
    swiper左右选项卡滑动
    table-cell使用
    返回和刷新
    电脑浏览器计算高度和宽度
    css 空格
    时间js
    Nodejs仿Apache的部分功能
    Nodejs中的JavaScript
  • 原文地址:https://www.cnblogs.com/zhaozhenzhen/p/14231360.html
Copyright © 2020-2023  润新知