【发布时间】:2018-06-15 04:27:22
【问题描述】:
我正在 laravel 中尝试这个 vuejs 应用程序,它是一个简单的应用程序,我在其中获取数据,然后尝试用 laravel 显示它,这是我的 messages.vue
Messages.vue
<template lang="html">
<div id="frame2">
<div id="contacts">
<ul>
<div v-for="privsteMsg in privsteMsgs">
<li class="contact">
<div class="wrap">
<span class="contact-status online"></span>
<img :src="'/uploads/imgs/avatars/' + privsteMsg.avatar">
<div class="meta">
<p class="name">{{privsteMsg.name}}</p>
<p class="preview">Hey it's me</p>
</div>
</div>
</li>
</div>
</ul>
</div>
</div>
</template>
<script>
export default {
props: ['userid'],
data() {
return {
privsteMsgs: [],
bUrl1: 'http://test.app:8000',
}
},
ready: function(){
this.created();
},
created(){
axios.get(this.bUrl1 + '/api/getMessages')
.then(response => {
app.privsteMsgs = response.data; //we are putting data into our posts array
console.log(app.privsteMsgs);
})
.catch(function (error) {
console.log(error); // run if we have error
});
},
}
</script>
奇怪的是console.log(app.privsteMsgs); 正常返回数据,但是当我尝试循环遍历它时,没有显示好像没有数据。
【问题讨论】:
-
你的
app变量是什么? -
对不起,什么应用变量?
-
app.privsteMsgs。你如何定义app?应该是this.privsteMsgs=... -
在您的代码中,您像
app.privateMsgs一样执行此操作,但您的app变量声明在哪里? -
那太尴尬了,自从我更改了文件后就没有更改过,谢谢大家