这看起来很愚蠢,但我的设置如下:
config/index.js
年:
module.exports = {
API_LOCATION: 'http://localhost:8080/api/'
}
在src/app.js
年后我有:
import Vue from 'vue'
import VueRouter from 'vue-router'
import VueResource from 'vue-resource';
Vue.use(VueRouter);
Vue.use(VueResource);
const App = require("./app.vue");
const home = require("./components/home.vue");
const config = require('../config');
window.config = config;
然后在src/components/home.vue
中,我有一个脚本块,使用它如下:
<script>
module.exports = {
data: function() {
return {
obj: null
}
},
created: function() {
this.$http.get(config.API_LOCAITON + '/call').then(res => {
// Do some business
}, res => {
// Handle some error
});
}
}
</script>
这是可行的,但我觉得用window
来处理应用程序配置是个坏主意.这里更规范的方法是什么?