vue api接口请求设置全局地址变量

1、创建全局文件
Global.vue

<script>
  //const serverSrc='http://200.200.0.1:8001';  //如果是本地调试运行状态请用这个地址
  const serverSrc = '..'; //如果是打包时请用这个
  export default {
    serverSrc
  }
</script>

2、全局引入
main.js

import global_ from './Global'   //引用
Vue.prototype.GLOBAL = global_;  //定义全局变量名

3、页面方法使用

//this.GLOBAL.serverSrc 全局地址
 slectList() {
        /*接口请求班级*/
        this.$http.post(this.GLOBAL.serverSrc + '/api/login/login1', {}, {
          headers: {},
          emulateJSON: true
        }).then((res) => {        
        }).catch(err => {         
        })
      },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章