抱歉,我是新手.
<select id="selectbox" @change="switchView(index)">
<option [v-for="(item, index) in items" v-bind:value="item.title"]>
{{ item.title }}
</option>
</select>
任何帮助都将不胜感激.
EDITED:
我需要索引,因为我有几个计算项目.我需要根据用户从项目中的 Select 更改视图.
抱歉,我是新手.
<select id="selectbox" @change="switchView(index)">
<option [v-for="(item, index) in items" v-bind:value="item.title"]>
{{ item.title }}
</option>
</select>
任何帮助都将不胜感激.
EDITED:
我需要索引,因为我有几个计算项目.我需要根据用户从项目中的 Select 更改视图.
你可以在select
元素上使用@change
,在indexOf函数的帮助下得到索引.这是工作demo.
参见代码:
var demo = new Vue({
el: '#demo',
data: function(){
return {
age: '',
selectedIndex: '',
options: [1,2,3,44,55]
};
},
methods: {
selected: function () {
this.selectedIndex = this.options.indexOf(this.age)
alert('this is selected Index ' + this.selectedIndex)
}
}
})