Vue3.0商店後臺管理系統項目實戰-vue3.0跨域問題的解決

接口
http://11x.21x.8x.3:8091/intmotx/1.json

vue.config.js

const { defineConfig } = require('@vue/cli-service')
// module.exports = defineConfig({
//   transpileDependencies: true,
//   lintOnSave:false
// })

module.exports = defineConfig({
  devServer: {
    proxy: {
      '/api': {
        target: 'http://11x.21x.8x.3:8091', //這裏填入你要請求的接口的前綴
        ws: true, //代理websocked
        changeOrigin: true, //虛擬的站點需要更換origin
        secure: true, //是否https接口,我用的http但是我變成false他打包後會報錯,所以先true
        pathRewrite: {
          '^/api': '' //重寫路徑
        }
      }
    }
  },
  lintOnSave:false
})

service.js

const Service = axios.create({
    timeout:8000,
    baseURL:"/api",
    headers:{
        "Content-type":"application/json;charset=utf-8",
      //  "Authorization":store.state.uInfo.userInfo.token
    }
})

request.js

// 獲取用戶列表
export const userListApi=data=>{ 
    return get({
        url:"/intmote/1.json",
        data
    })
} 

代理成功


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章