vue操作select獲取option值


如何實時的獲取你選中的值 只用@change件事
@change="changeProduct($event)" 動態傳遞參數
vue操作select獲取option的ID值

 

如果select的v-model(value)與option綁定的value值一致。
那么就會顯示option中的值 {{item.title}}-->

<div id="app">
       <select  class="fl" v-model="ProductActive"  @change="changeProduct($event)" >
            <option v-for="(item,index) in productList" :key="index" :value='item.id'>{{item.title}}</option>  
       </select>  
  </div>
data:{
        productList:[{id:1,title:"北京"},{id:2,title:"上海"},{id:3,title:"廣州"},{id:4,title:"四川"}],
        ProductActive:"1",//獲取被選中的value值 默認選中的是1(北京)
     },
                
  methods: {
           changeProduct(event) {
             this.ProductActive = event.target.value; //獲取option對應的value值
             console.log("你選中了",this.ProductActive)
           },
       }

 

 


免責聲明!

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



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