美文网首页
Vue3.0商店后台管理系统项目实战-vue3.0跨域问题的解决

Vue3.0商店后台管理系统项目实战-vue3.0跨域问题的解决

作者: 祈澈菇凉 | 来源:发表于2022-10-18 11:12 被阅读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
        })
    } 
    

    代理成功


    相关文章

      网友评论

          本文标题:Vue3.0商店后台管理系统项目实战-vue3.0跨域问题的解决

          本文链接:https://www.haomeiwen.com/subject/fsxdzrtx.html