服务器上接收的数据为[{ "name":"TOM" , "age":"16" },{ "name":"JACK" , "age":"18" },{ "name":"marry" , "age":"20" }]
我觉得是html中的循环代码有问题,请问哪里出错了?
<ul v-for="item in items">
<li>{{ item.name }}</li>
<li>{{ item.age }}</li>
</ul>
export default {
data () {
return {
header:'',
items: [
{
name:'',
age:''
}
]
}
},
methods:{
postdata(){
var user_id = this.getcookies('user_id');
this.$http.post('http://example.com/user',{
userID:user_id
}).then(function(data){
this.items=data.body.data
}
)
}
}
}
循环没问题啊,this.items拿到的是错的啊。属于this指向问题,你并没有成功赋值呢