【发布时间】:2019-07-30 01:34:37
【问题描述】:
我目前正在尝试使用数据和自定义项目文本填充我的 Vue 项目的 v-select。
我发现使用 v-for 在列表中有效,但在我的 v-select 模板中无效。
作品:
<ul id="example-1">
<li v-for="item in appointments">
ID: {{ item.id }} | {{ item.client_name }}
</li>
</ul>
显示:
- ID: 1 | John Smith
- ID: 2 | Carl Larson
- ID: 3 | Lennard Smith
然后是我的工作选择,它没有使用模板(有效):
<v-select
v-model="form.lead_generator_id"
prepend-icon="person"
:items="appointments"
label="Appointment Setter"
item-value="id"
item-text="client_name"
></v-select>
然后是我的模板 v-select:
<v-select
v-model="form.lead_generator_id"
prepend-icon="person"
:items="appointments"
label="Appointment Setter"
item-value="id"
item-text="client_name"
>
<template slot="selection" slot-scope="appointments" v-for="item in appointments">
ID: {{ item.id }} | {{ item.client_name }}
</template>
<template slot="item" slot-scope="appointments" v-for="item in appointments">
ID: {{ item.id }} | {{ item.client_name }}
</template>
</v-select>
最后一个的问题是它显示(在选择框中):
ID: 3 | Lennard Smith
ID: 3 | Lennard Smith
ID: 3 | Lennard Smith
我正在通过 axios 从我的 API 收集信息,然后 storign 位于 data() 中,它返回 appointments: [],
我的 api 返回:
{
"status":"ok",
"appointments":[
{ "id": 1, "client_name": x, etc.. }
{ "id": 2, "client_name": x, etc.. }
],
}
请帮助我了解如何让它正确显示。
【问题讨论】:
-
这是使用Vuetify's
v-select还是其他一些组件? -
是的,它正在使用 v-select @Phil 。我发现不使用 v-select 时使用选项确实有效。
标签: javascript vue.js vuetify.js