【发布时间】:2017-09-02 04:11:05
【问题描述】:
我正在尝试从 rest api 获取一些数据。然而,结果 this.someData 仍未定义。
我的组件如下
<template>
<div class="list">
<h1>List</h1>
<pre>msg: {{msg}}</pre>
</div>
</template>
<script>
import Vue from 'vue'
import VueResource from 'vue-resource'
Vue.use(VueResource)
export default {
name: 'list',
data () {
this.$http.get('http://localhost:8080/api/posts/filter?username=tons').then(response => {
// get body data
this.someData = response.body
console.log(this.someData)
}, response => {
// error callback
})
return {
msg: this.someData + 'somedata'
}
}
}
</script>
有人知道我做错了什么吗?
【问题讨论】:
-
如果您在浏览器中转到
http://localhost:8080/api/posts/filter?username=tons,您会看到结果吗?
标签: vue.js vue-resource