在vue项目中设置BASE_URL

在vue项目中设置BASE_URL

  1.在config文件夹中新建global.js文件

const BASE_URL = 'http://192.168.1.62:8080/rest/'
export default {
  BASE_URL
}

  2.在入口文件中引入,设置为全局变量

import global_ from '../config/global.js'
Vue.prototype.GLOBAL = global_;

  3.在有需要的地方引入baseUrl

created() {
    const baseUrl=this.GLOBAL.BASE_URL
    // const classId=this.$route.query.classId
    console.log(baseUrl)
  },
http://192.168.1.62:8080/rest/  //这个是上面打印的baseUrl
原文地址:https://www.cnblogs.com/cb1490838281/p/9717449.html