1

I am trying Vue.js, everything looks great other than working with select inputs within components. I created a basic fiddle setup to illustrate the problem : https://jsfiddle.net/8f24xLdq/

    <div class="panel-body" id="vue">
  <example></example>
</div>
<script type="text/x-template" id="t">
  <div>
    <select v-bind="selected">
      <option v-for="option in options" v-bind:value="option.value">
        {{ option.text }}
      </option>
    </select>
    <span>Selected: {{ selected }}</span>
  </div>
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.10/vue.js"></script>
<script>
  Vue.component('example', {
    template: "#t",
    data: function() {
      return {
        selected: 'A',
        options: [{
          text: 'One',
          value: 'A'
        }, {
          text: 'Two',
          value: 'B'
        }, {
          text: 'Three',
          value: 'C'
        }]
      }
    }
  });

  new Vue({
    el: "#vue"
  });

</script>

2 Answers 2

2

Use v-model instead of v-bind in <select >

<select v-model="selected">
Sign up to request clarification or add additional context in comments.

Comments

0
  <div class="col-md-6">
    <select v-model="selectedto">
      <option v-for="option in estados" v-bind:value="option.id" :key="option.id" v-html="option.label">
      </option>
    </select>
    <span v-html="selectedto"></span>
  </div>

  mounted: function () {
     console.log('created', this);
     var vm = this;
     vm.$root.selectedto = 1;
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.