组件 child.vue中
mounted() {
console.log(this.apiUrl)
},
main.js
function getServerConfig() {
axios.get("serverconfig.json").then(res => {
console.log(res.data.url);
Vue.prototype.apiUrl = res.data.url;
});
}
async function init() {
await getServerConfig();
new Vue({
render: h => h(App)
}).$mount("#app");
}
init();
打印结果