【发布时间】:2019-05-16 18:34:08
【问题描述】:
尝试使用 vue-resource 但我正在解决标题中描述的错误。下面的代码在名为 network.js 的 utils 部分中:
import VueResource from 'vue-resource'
const getConfig = () =>{
console.log('its working');
// GET /someUrl
this.$http.get('https://fdsdfsdf-685a-45ed-8665-9847e0dbce0d.mock.pstmn.io/getConfig')
.then(response => {
// get body data
this.config = response.body;
}, response => {
// error callback
});
};
//Export login so other classes can use it
export{
getConfig
}
这就是它被调用的代码。它存在于我的一条名为Admin.vue 的路线中:
<template>
<div class="admin">
<h1>This is admin page area</h1>
<p>This is the data: {{this.config}}</p>
</div>
</template>
<script>
import{getConfig} from "../utils/network";
export default{
data: function () {
return {
config: [{}]
}
},
created:function(){
getConfig();
}
}
</script>
我正在按照他们在示例中描述的方式使用它,但我不确定我缺少什么?
【问题讨论】:
标签: vue.js vuejs2 vue-resource