Vuejs2 返回空数组的Api路由
即使表中包含数据,返回空数组的Api路由。 我想列出用户。路由模型绑定失败 这是我的api路线Vuejs2 返回空数组的Api路由,vuejs2,laravel-5.4,Vuejs2,Laravel 5.4,即使表中包含数据,返回空数组的Api路由。 我想列出用户。路由模型绑定失败 这是我的api路线 Route::middleware('auth:api')->get('/users',function(){ return App\User::get(); }); 这是刀片模板中使用的我的vue组件 <template> <div class="row" style="min-height:250px;"> &
Route::middleware('auth:api')->get('/users',function(){
return App\User::get();
});
这是刀片模板中使用的我的vue组件
<template>
<div class="row" style="min-height:250px;">
<ul>
<li v-for="user in users">
@{{user.name}}
</li>
</ul>
</div>
</template>
<script>
export default{
data() {
return {
users : [],
}
},
ready: function(){
this.getUsers();
},
methods: {
getUsers: function(response){
axios.get('http://localhost:8000/api/users')
.then(response => {
this.users = response.data;
})
.catch(error => {
});
},
},
}
</script>
-
@{{user.name}
导出默认值{
数据(){
返回{
用户:[],
}
},
就绪:函数(){
这是getUsers();
},
方法:{
getUsers:函数(响应){
axios.get()http://localhost:8000/api/users')
。然后(响应=>{
this.users=response.data;
})
.catch(错误=>{
});
},
},
}
这是我的错误。vuejs 2中不推荐使用ready,而是使用mounted。我不明白。axios.get在没有得到任何401(未经授权)响应的情况下为您工作?