vue實現 select 下拉框點擊選項觸發事件


 

注意不要使用 @click 點擊事件會不生效,使用 @click.native

 

 

 

獲取option的ID值

1.html部分

<select  class="bw1 bss bc4 h40px w100 dib br4 fl" v-model="ProductActive"  @change="changeProduct($event)" >
       <option value="0">商品名稱</option>  
       <option v-for="(item,index) in productList" :key="index"  :value='item.id'>{{item.title}}</option>  
</select>  

  

2.javascript部分

 <script>
    export default {
        data() {
            return {
                ProductActive: 0, //商品名稱當前選中項
                productList: [],
            }

        },
        methods: {
            changeProduct(event) {
                this.ProductActive = event.target.value; //獲取商品ID,即option對應的ID值
            },
        }
    }
</script>

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM