vue给option加点击事件问题

            <select v-model="value" @change="configData(index)" placeholder="请选择轨道">
                <option
                    v-for="(item,index) in headData"
                    :key="item.value"
                    :value="item.value">
                </option>
            </select>

因为直接在option加click事件是不触发的,所以改为change事件,但是我想拿到option的index,然后给configData传参数,有没有办法

阅读 16.2k
3 个回答

你的index不是和value一样的吗? 直接拿value就可以了

<template>
  <div class="hello">
    <h1>Hello</h1>
    <p>{{$store.state.count}}</p>
    <select v-model="selected" @change="configData(selected)" placeholder="请选择轨道">
      <option v-for="(item,index) in headData" :value="index">
        {{ item.value }}
      </option>
    </select>
  </div>
</template>
<script>
  export default{
    data () {
      return {
        headData: [{
          value: 'a'
        }, {
          value: 'b'
        }],
        selected: ''
      }
    },
    methods: {
      configData (index) {
        console.log(index)
        console.log(this.headData[index].value)
      }
    }
  }
</script>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题