【发布时间】:2018-09-08 01:05:40
【问题描述】:
我的项目的/src/static/js 目录中有一个server_config.json。
{
"ApiUrl":"http://localhost:8000"
}
在我的main.js,我想用axios来获取数据:
Vue.prototype.getConfigJson = function () {
this.$http.get("/static/js/server_config.json").then((response)=> {
Vue.prototype.ApiUrl = 'http://localhost:8000';
}).catch((response)=> {
if (response == null) {
Vue.prototype.ApiUrl = 'http://localhost:8000';
}
});
}
在我的App.vue 中发出函数:
<template>
<div id="app">
<router-view/>
</div>
</template>
<script>
export default {
mounted: function () {
this.getConfigJson();
}
}
</script>
但我无法获取 json 数据,我会抓住这个:
catch((response)=> {}
response 是 undefined。
【问题讨论】:
-
您应该检查浏览器开发工具的网络面板以了解请求。