新建一個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))
}}
)