Vuejs2 vue中的Loop-over方法
我希望能够循环查看给定客户年/月的所有发票 我在DRF中使用django_过滤器在后端执行一些过滤,我的端点如下所示:Vuejs2 vue中的Loop-over方法,vuejs2,django-rest-framework,axios,Vuejs2,Django Rest Framework,Axios,我希望能够循环查看给定客户年/月的所有发票 我在DRF中使用django_过滤器在后端执行一些过滤,我的端点如下所示: // in a template: <div v-for="invoice in invoices" :key="invoice.id"> // here is a component(s) for showing invoice content </div> ... // in a component: data: { return {
// in a template:
<div v-for="invoice in invoices" :key="invoice.id">
// here is a component(s) for showing invoice content
</div>
...
// in a component:
data: {
return {
invoices: []
}
},
methods: {
async retrieveResults() {
const { data: invoices} = await this.$axios.$get('/invoices/', {
params: {
client: this.client,
month: this.month,
year: this.year,
},
});
this.invoices = invoices
}
}
所有发票:
过滤器:
我有一个基于过滤器获取结果的方法,还有一个watch属性,用于在正确的时间检索数据,在本例中选择了月份
methods: {
retrieveResults() {
this.$axios.$get('/invoices/', {
params: {
client: this.client,
month: this.month,
year: this.year,
},
});
},
},
watch: {
month: {
handler: 'retrieveResults',
},
},
我得到的答复如下(简化):
一切都按预期进行,我在“网络”选项卡中看到了正确的结果,具体取决于选项,我的问题是如何在这上面进行v-for循环?我尝试了很多方法,但到目前为止没有任何效果
我尝试将检索结果
包装到vuetify v-data-table中,但没有成功。类似这样的内容:
// in a template:
<div v-for="invoice in invoices" :key="invoice.id">
// here is a component(s) for showing invoice content
</div>
...
// in a component:
data: {
return {
invoices: []
}
},
methods: {
async retrieveResults() {
const { data: invoices} = await this.$axios.$get('/invoices/', {
params: {
client: this.client,
month: this.month,
year: this.year,
},
});
this.invoices = invoices
}
}
//在模板中:
//以下是用于显示发票内容的组件
...
//在组件中:
数据:{
返回{
发票:[]
}
},
方法:{
异步检索结果(){
const{data:invoices}=wait this.$axios.$get('/invoices/'){
参数:{
客户:这个客户,
月:这个月,
年份:今年,
},
});
这是发票
}
}
感谢您的见解,我的结果略有不同,但您的评论为我指明了正确的方向。