Help us understand the problem. What is going on with this article?

Vueで<select>タグを使う時に、選択されているvalue属性をスクリプトで決定する方法について。

Vue
v-modelを使います。

概要:
select 要素v-modelにした変数に対して、option 要素に設定されたvalueと同じ値を代入すれば良い。

html
<select v-model="selectNumber" v-on:change="selectIndex">
    <option v-for="item in valueList" v-bind:value="item.number">{{item.title}}</option>
</select>
vue_component
var vueComponent = {
  data: {
    //
    // @note: v-modelに束縛、ここで選択状態の初期化も行う。
    //
    selectNumber: 1,

    //
    // @note: 選択項目にするデータ
    //
    valueList: [{title:"one", number:1},{title:"two", number:2}],
  },

  method: {
    //
    // @note: ここでスクリプト側から select 要素の選択状態を設定する。
    //
    setSelectNumber: function(idx){
      // selectのv-modelで束縛した変数に value属性の値を代入すれば実際に変更される。
      this.selectNumber = valueList[idx].number;
    }
  }
}
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away