Vue.js Laravel和VueJs:无法设置属性';猫';未定义的
我在刀片中有以下代码:Vue.js Laravel和VueJs:无法设置属性';猫';未定义的,vue.js,laravel-5,axios,Vue.js,Laravel 5,Axios,我在刀片中有以下代码: <list-categories-component></list-categories-component> 我将this.cats=response.data.cats更改为this.cats=response.data以捕获数组本身,但仍然得到相同的错误 我正在运行npm run watch那么这里有什么问题以及如何解决它呢?在中更改函数,然后将和catch更改为箭头函数,以便将此读取为vue组件: 方法:{ fetchTaskList()
<list-categories-component></list-categories-component>
我将this.cats=response.data.cats
更改为this.cats=response.data
以捕获数组本身,但仍然得到相同的错误
我正在运行
npm run watch
那么这里有什么问题以及如何解决它呢?在中更改函数,然后将和catch
更改为箭头函数,以便将此
读取为vue组件:
方法:{
fetchTaskList(){
get(“/api/listCats”)
。然后(响应=>{
console.log(response.data.cats);
this.cats=response.data.cats;
})
.catch(错误=>{
//处理错误
console.log(错误);
});
}
}
非常感谢。我真的很感激。
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Example Component</div>
<div class="card-body">
<ul>
<li v-for="cat in cats" :key="cat.cat_id">{{cat.cat_en_title}}</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data(){
return{
cats:[],
};
},
created() {
this.fetchTaskList();
},
methods:{
fetchTaskList(){
axios.get('/api/listCats')
.then(function (response) {
console.log(response.data.cats);
this.cats = response.data.cats;
})
.catch(function (error) {
// handle error
console.log(error);
});
}
}
}
</script>