解決vue中的跨域問題(Axios請求)

報錯
在這裏插入圖片描述

  1. 配置BaseUrl 找到目錄(src->main.js)
Axios.defaults.baseURL = '/api';
  1. 配置代理 找到目錄(config->index.js)
    在這裏插入圖片描述
'/api':{
        target: ' ',  //自己的域名
        changeOrigin: true,  //是否跨域
        pathRewrite: {
          '^/api': ''  //需要rewrite重寫的
        }
      }
  1. 在使用axios修改一下url
 created (){
    this.$axios.post('/openapi/api',{
    }).then(res=>{
      console.log(res);
    })
  },
  1. 需要重新啓動項目,ok啦
    在這裏插入圖片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章