Vuetify v-select attribute type check fails
P粉988025835
P粉988025835 2023-09-04 15:59:13
0
1
499
<p>When I use v-select in Vuetify 3, I often encounter the following error: </p> <blockquote> <p>[Vue warning]: Invalid prop: Type check failed for prop 'title'. Expected String | Number | Boolean but got Object</p><p> In <VListItem key=0 title=`</p> </blockquote> <p>I'm not sure what the problem is. I'm getting an array of objects from a backend API as my JSON response. My goal is to display all the usernames in the dropdown, but when I select an item in the dropdown, I want to store the entire object in a variable. For example, if I select the "Desmond" username in the dropdown menu, I want the objects related to Desmond to be stored, i.e. <code>{"username": "Desmond","email": " desmond@test.com"}</code></p> <pre class="lang-js prettyprint-override"><code><v-select v-model="selectedItem" :items="items" name="username" item-text="username" label="Select Item" return-object ></v-select> </code></pre> <pre class="brush:php;toolbar:false;"><script> import axios from "axios"; export default { name: "Testing123", data() { return { items: [], selectedItem: null, }; }, created() { this.fetchItems(); }, methods: { fetchItems() { axios .get("http://localhost:5000/items", config) .then((response) => { this.items = response.data }) .catch((error) => { console.error(error); }); },</pre> <p>This is my<code>response.data</code></p> <pre class="brush:php;toolbar:false;">[ { "username": "Eric", "email": "eric@test.com", }, { "username": "Desmond", "email": "desmond@test.com", }, ]</pre></p>
P粉988025835
P粉988025835

reply all(1)
P粉707235568

You are using :item-text, which is the property name in Vuetify v2, see here for details.

In v3, this property has been renamed to :item-title.

Change the name and it will work:

<v-select
  item-title="username" 
  ...
></v-select>

Examples can be seen in playground.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!