zoukankan      html  css  js  c++  java
  • Vue3 axios跨域配置

    安装axios

    npm install axios vue-axios

    main.js里

    import axios from 'axios'
    import VueAxios from 'vue-axios'
     
    const app = createApp(App) // 创建实例
     
    app.config.globalProperties.$axios = axios
    axios.defaults.baseURL = '/aposServer'
    axios.defaults.headers.post['Content-Type'] = 'application/json';
    
    app.config.productionTip = false
    app.use(VueAxios,axios);

    在package.json同级目录下加个vue.config.js文件

    module.exports = {
      devServer: {
        proxy: {
          '/aposServer': {
              target: 'https://localhost:44310/api', //API服务器的地址
              changeOrigin: true,
              pathRewrite: {
                  '/aposServer': ''
              }
          }
      },
      }
    }

    调用webapi

    this.$axios.post("/Equipments/GetAllEquipmentsTest")
    .then(res=>{
       console.log(res)
    })
    .catch(err=>{
       console.log(err)
    })
                }

    重启下服务

  • 相关阅读:
    19.将写好的输出到本地 文件格式:Step
    18.对Topo进行打孔
    17.球体
    16.圆柱
    15.绘制圆锥
    14.Chamfer把正方体所有的边倒角
    13.绘制一个方体
    ①②坐标点
    esp8266接线
    IP解析
  • 原文地址:https://www.cnblogs.com/czly/p/14480485.html
Copyright © 2011-2022 走看看