vue全局url

it2022-05-08  8

方法1、api.js

const LoginURL = 'http://***.***.*.**:9090' export default { LoginURL, }

然后到main.js去挂载

import global_ from '@/api' Vue.prototype.global = global_

需要用到的页面

console.log(this.global.LoginURL)

 

方法2、api.js

const baseURL = 'http://wx.***:6062' const APILIST = { homeSlideshow: '/index/getIndexData', newsList: '/index/getNewList' } const base = function () { let api = {} for (let k in APILIST) { api[k] = baseURL + APILIST[k] } return api } export default { INTERFACES: base() }

照样去main.js挂载,然后使用的时候

console.log(this.global.INTERFACES.homeSlideshow)

个人推荐第二种写法,这样修改接口的时候就不用一个个页面找


最新回复(0)