第一步:在 static
文件夾中新建一個 config.json,
編輯配置(static文件下可被直接訪問)
{ "base_url": "http://systemManage.com" }
第二步:在 main.js
中請求定義的配置文件,並放到 Vue.prototype
中,使全局可訪問。
import axios from 'axios' axios.get('/static/config.json').then((res) => { Vue.prototype.base_url = res.base_url; new Vue({ el: '#app', router, store, components: { App }, template: '<App/>' })
})
第三步:調用
1.在 .vue
文件中使用:
console.log(
this.
base_url)
2.
在 .js
文件中,可以調用Vue后再使用:
import Vue from 'vue' console.log(Vue.prototype.base_rul)
轉載於:https://www.cnblogs.com/webhmy/p/9517680.html