question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Single Select does not sync with given value or v-model

See original GitHub issue

Options are a array of objects and value/v-model is a object. If I change the value the original is not changed. Works for multiple select very well!

https://codepen.io/anon/pen/eRRLPB HTML:

<div id="app">
  <h1>Vue Select</h1>
  {{ item }}
  <v-select :value.sync="item" :options="options"></v-select>
</div>

JS:

Vue.component('v-select', VueSelect.VueSelect)

new Vue({
  el: '#app',
  data: function () {
    return {
      item: { label: 'a', value: 1},
      options: [
        { label: 'a', value:1},
        { label: 'b', value: 2},
        { label: 'c', value: 3},
        { label: 'd', value: 4},
        { label: 'e', value: 5}
      ]
    }
  }
})

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
devmountcommented, Jun 27, 2017

You’re using the latest Vue (2.x) – .sync is an old modifier from Vue 1.x. See the docs:

This is convenient, however it leads to maintenance issues in the long run because it breaks the one-way data flow assumption: the code that mutates child props are implicitly affecting parent state. This is why we removed the .sync modifier when 2.0 was released.

The proper way would be to just use the v-model directive instead of :value.sync:

<div id="app">
  <h1>Vue Select</h1>
  {{ item }}
  <v-select v-model="item" :options="options"></v-select>
</div>

https://codepen.io/devmount/pen/jwaBYe

I would recommend to read about the “Form Input Binding” in Vue 2.x in the docs.

1reaction
mgurleycommented, Oct 2, 2017

@sagalbot Thanks, I preprocessed the submission of my model to convert the object to its value. And that worked. Plus serialization on the sever side of the value into an object, so the value is selected upon load. All good.

Read more comments on GitHub >

github_iconTop Results From Across the Web

using v-model on <select> makes first option not appear in ...
When they select an option, I'm using v-model to send that value to the data variable 'name' (will be using this for other...
Read more >
What you should know about Vue v-model - LearnVue
Vue v-model is a directive that creates a two-way data binding between a value in our template and a value in our data...
Read more >
Form Input Bindings - Vue.js
v -model will ignore the initial value , checked or selected attributes found on any form elements. It will always treat the current...
Read more >
Using v-model for Two-Way Binding in Vue.js | DigitalOcean
To bind the value of an input element to a property of your component's data, use v-model="dataProperty" like so.
Read more >
Table | Components - BootstrapVue
Internally, the value of the field key specified by the primary-key prop is used as the Vue :key value for each rendered item...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found