新建一个Vue实例,在created方法中使用axios发起异步请求
var app = new Vue({
el:"#app",
data :{
message: 'Hello Vue!',
goods:[]
},
created(){ axios.get('/goods/homeGoods').then(function(response) {
this.goods=response.data
console.log(this.goods.catelogGoods1)
// console.log(response);
//在这里需要bind(this),才能访问到Vue实例中的data
}.bind(this))
}}
)