v-suggest icon indicating copy to clipboard operation
v-suggest copied to clipboard

Set default selection from list

Open tikvarova opened this issue 5 years ago • 2 comments

Dear Terry,

What is the best way to set default value(selection) from a props?

10X in advance

tikvarova avatar Aug 17 '20 13:08 tikvarova

Use v-model directive directly.

Some code for example below

<v-suggest
  show-field="name"
  v-model="userName"
  :data="list"
 >
</v-suggest>

<script>
export default {
  data () {
    return {
      list: [
        { name: 'tom' },
        { name: 'jerry' },
      ]
      userName = 'jerry'
    }
  }
}
</script>

TerryZ avatar Aug 20 '20 08:08 TerryZ

Dear Terry,

Thanks for the answer, but what will be the proper solution if we need to set "row", not only "text". For example at the moment I use wrapper component which holds v-suggest. I use props to set list items and current object:

The list contains data in simmilar format:


// List object is similar to:
{
  id: 1, name: "test1",
  id: 2, name: "test2",
  id: 3, name: "test3",
  id: 4, name: "test4",
  ...
  ...
  ...
}

Then in wrapper component I use some parameters like:

ref="suggested" :key-field="keyField" :data="list" @values="values" @clear="$emit('clear')" :show-field="showField":full-list="true" etc.

and than use something like this:


 

It works, but I want to check if there is better way to do this!

Thanks in advance

tikvarova avatar Aug 22 '20 21:08 tikvarova