【发布时间】:2019-05-17 07:14:12
【问题描述】:
我在邮递员中设置了一个假的 mocke 服务器来获取我的 vue 应用程序的 som 测试数据。这是我从服务器得到的:
我想访问数据信息,但我很难做到。这是我正在使用的代码:
<template>
<div class="admin">
<h1>This is admin page area</h1>
<JsonEditor :objData="config" v-model="config" ></JsonEditor>
</div>
</template>
<script>
import{getConfig} from "../utils/network";
import Vue from 'vue'
import JsonEditor from 'vue-json-edit'
Vue.use(JsonEditor)
export default{
data: function () {
return {
config:{}
}
},
created:function(){
getConfig()
.then(response => {
console.log(response)
this.config = response;
})
.catch(err => {
console.log(err)
})
}
}
</script>
我尝试过response.data,但没有成功。我正在将它提供给 json 编辑器,但它目前无法显示 json。它是空的。这是我的网络调用代码:
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)
const getConfig = () =>{
return Vue.axios.get('https://8db51a11-752e-4d64-b237-8195055fbf26.mock.pstmn.io')
};
//Export getConfig so other classes can use it
export{
getConfig
}
我错过了什么?
【问题讨论】:
-
你应该使用
async/await