Vue.js nuxt.js正在将数据提取到vuetify表
我在vuetify表中获取数据时遇到了问题,它没有在边表中显示任何数据。 我的Laravel API 路由::获取(“/businesslist”, 'BusinessController@userlist')->name('businesslist') Laravel API控制器 Nuxt代码Vue.js nuxt.js正在将数据提取到vuetify表,vue.js,vuejs2,axios,vue-component,vuetify.js,Vue.js,Vuejs2,Axios,Vue Component,Vuetify.js,我在vuetify表中获取数据时遇到了问题,它没有在边表中显示任何数据。 我的Laravel API 路由::获取(“/businesslist”, 'BusinessController@userlist')->name('businesslist') Laravel API控制器 Nuxt代码 营养 导出默认值{ 数据(){ 返回{ 搜索:“”, 标题:[ {文本:'SL,No',值:''}, {text:'Name',value:'Name'}, {文本:'Mobile',值:'Mobi
营养
导出默认值{
数据(){
返回{
搜索:“”,
标题:[
{文本:'SL,No',值:''},
{text:'Name',value:'Name'},
{文本:'Mobile',值:'Mobile_number'},
{text:'Location',value:'Location'},
{文本:“加入日期”,值:“注册日期”},
{文本:'更新日期',值:'注册\更新\日期'},
],
登记册:[
],
}
get(“/Businessregisterlist”)
。然后(res=>this.registerlist=res.data.registerlist)
},
}
首先,您必须在如下函数中调用
API
:
<script>
export default {
data() {
return {
list: []
}
},
methods: {
callAPI() {
axios.get('/', then(function(res){
this.list = res.data.registerList;
}))
}
},
mounted(){
this.callAPI(); // if you need that List on load then you can use mounted() otherwise that function will call during event.
}
}
</script>
导出默认值{
数据(){
返回{
名单:[]
}
},
方法:{
callAPI(){
获取('/',然后(函数(res){
this.list=res.data.registerList;
}))
}
},
安装的(){
this.callAPI();//如果需要加载该列表,则可以使用mounted(),否则该函数将在事件期间调用。
}
}
在这里,在
then()
中,我认为最好使用function()
。因为若你们使用函数,那个么它将指示这个对象。因此,我们可以轻松访问所有对象属性(如:data()、methods()等)。使用中的函数。然后(function(res){})
,因为这个
在ES6语法中可以表示全局对象。@Perfectismist先生,请您发布您的答案,以便更好地理解。我在我的代码中实现了你的代码没有错误,但是数据没有显示,你的控制台中有数据吗?then(function(res){console.log(res.data.registerlist);}))
perfectismist我在控制台、属性或方法“registerlist”中遇到了这个错误未在实例上定义,但在呈现过程中被引用。此错误表明没有注册表项。所以,console.log(res.data)
。有那个名字的名单吗?
<template>
<v-card>
<v-card-title>
Nutrition
<v-spacer></v-spacer>
<v-text-field
v-model="search"
append-icon="mdi-magnify"
label="Search"
single-line
hide-details
></v-text-field>
</v-card-title>
<v-data-table
:headers="headers"
:items="registerlist"
:search="search"
></v-data-table>
</v-card>
</template>
<script>
export default {
data () {
return {
search: '',
headers: [
{ text: 'SL,No', value: '' },
{ text: 'Name', value: 'name' },
{ text: 'Mobile ', value: 'mobile_number' },
{ text: 'Location ', value: 'location' },
{ text: 'Join Date ', value: 'registration_date' },
{ text: 'Renewal Date ', value: 'registration_renewal_date' },
],
registerlist: [
],
}
axios.get('/Businessregisterlist')
.then(res => this.registerlist = res.data.registerlist)
},
}
</script>
<script>
export default {
data() {
return {
list: []
}
},
methods: {
callAPI() {
axios.get('/', then(function(res){
this.list = res.data.registerList;
}))
}
},
mounted(){
this.callAPI(); // if you need that List on load then you can use mounted() otherwise that function will call during event.
}
}
</script>