zoukankan      html  css  js  c++  java
  • proxy解决跨域问题

    首先我们在本地开发,域名都是localhost,当我们需要请求后台数据时,就会出现跨域的问题

    下面就是在vue.config.js配置文件里:

    devServer: {

        proxy: {
          // detail: https://cli.vuejs.org/config/#devserver-proxy
          '/api': {
            target: `http://10.24.4.214:8098/api`,
            changeOrigin: true,
            pathRewrite: {
              '^/api' ''
            }
          }
        }
    }
    /api表示需要去匹配请求时的url,然后替换成target的值
    比如你页面里是写的:
    axios.post('/api/list/gd')
    最终node去请求后台的地址是:http://10.24.4.214:8098/api/list/gd
    但是你在浏览器里看到的还是:http://localhost:8888/api/list/gd,这时候就不存在跨越的问题的,node服务已经代理拿到数据了
    白日不到处,青春恰自来,苔花如米小,也学牡丹开。
  • 相关阅读:
    [Leetcode]@python 76. Minimum Window Substring
    [Leetcode]@python 75. Sort Colors
    HTNL表单
    第二天
    开学心德
    HTML表单
    网页制作
    2nd day
    开课心得
    CF10D/POJ2127 LCIS 题解
  • 原文地址:https://www.cnblogs.com/yihuanhuan/p/14543308.html
Copyright © 2011-2022 走看看