Laravel 从对象vuejs数组中获取第一个对象
如何获取对象第一个对象id的数组? 这是我的arrray的内容 0:{id:1,用户id:1,用户id:2,创建地址为:“2021-03-22T16:37:10.000000 Z”,…} 1:{id:7,user_id:1,user2_id:3,创建地址为:“2021-03-24T16:24:47.000000 z”,…} 2:{id:8,user_id:1,user2_id:1,创建地址为:“2021-03-24T18:19:21.000000Z”Laravel 从对象vuejs数组中获取第一个对象,laravel,vue.js,Laravel,Vue.js,如何获取对象第一个对象id的数组? 这是我的arrray的内容 0:{id:1,用户id:1,用户id:2,创建地址为:“2021-03-22T16:37:10.000000 Z”,…} 1:{id:7,user_id:1,user2_id:3,创建地址为:“2021-03-24T16:24:47.000000 z”,…} 2:{id:8,user_id:1,user2_id:1,创建地址为:“2021-03-24T18:19:21.000000Z” 导出默认值 { 数据(){ 返回{
导出默认值
{
数据(){
返回{
convs_id:[],
convs:[],
}
},
创建(){
这个.fetchConversation();
this.convs_id=this.convs[0].id;
console.log(this.convs_id);
},
方法:
{
fetchConversation()
{
get('getConvs')。然后(响应=>{
this.convs=response.data;
});
}
}
}
当获取数据的调用已解决时,将填充此.convs
。因此,为了使用它,您必须等待该承诺得到解决
为了能够等待承诺,您必须返回它。因此fetchConversation()
需要返回axios.get()
(这是您将等待的承诺):
方法:{
fetchConversation(){
返回axios.get('getConvs')。然后(响应=>{
this.convs=response.data;
});
}
}
现在,fetchConversation()
返回承诺,您有两种等待方法:要么创建created
async
,要么使用:
async created(){
等待此消息。fetchConversation();
console.log(this.convs[0]);
}
或按承诺调用方法:
created(){
this.fetchConversation()。然后(()=>{
console.log(this.convs[0]);
})
}
当获取数据的调用已解决时,将填充此.convs
。因此,为了使用它,您必须等待该承诺得到解决
为了能够等待承诺,您必须返回它。因此fetchConversation()
需要返回axios.get()
(这是您将等待的承诺):
方法:{
fetchConversation(){
返回axios.get('getConvs')。然后(响应=>{
this.convs=response.data;
});
}
}
现在,fetchConversation()
返回承诺,您有两种等待方法:要么创建created
async
,要么使用:
async created(){
等待此消息。fetchConversation();
console.log(this.convs[0]);
}
或按承诺调用方法:
created(){
this.fetchConversation()。然后(()=>{
console.log(this.convs[0]);
})
}
在请求成功回调中提取第一项:
export default
{
data(){
return {
convs_id: null,
convs: [],
}
},
created(){
this.fetchConversation();
},
methods:
{
fetchConversation()
{
axios.get('getConvs').then(response=>{
this.convs = response.data;
let [firstConvs]=this.convs;// es6 syntax of destructing the array
this.convs_id = firstConvs.id;
});
}
}
}
在请求成功回调中,提取第一项:
export default
{
data(){
return {
convs_id: null,
convs: [],
}
},
created(){
this.fetchConversation();
},
methods:
{
fetchConversation()
{
axios.get('getConvs').then(response=>{
this.convs = response.data;
let [firstConvs]=this.convs;// es6 syntax of destructing the array
this.convs_id = firstConvs.id;
});
}
}
}