TerryZ / v-suggest

A Vue2 plugin for input content suggestions, support using keyboard to navigate and quick pick, it make use experience like search engine input element
https://terryz.github.io/vue/#/suggest
MIT License
76 stars 16 forks source link

Set default selection from list #20

Open tikvarova opened 4 years ago

tikvarova commented 4 years ago

Dear Terry,

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

10X in advance

TerryZ commented 4 years ago

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>
tikvarova commented 4 years ago

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:


  Githubissues.
            
  • Githubissues is a development platform for aggregating issues.