實(shí)際項(xiàng)目中我們獲取選擇的數(shù)據(jù)的id;這時(shí)候 需要配合使用v-bind,才能獲取到選擇的那條數(shù)據(jù)的id值,其實(shí)就是id賦值給value屬性
<template> <div> <select v-model="select" > <option v-for="(a,index) in arr" :key="index" :value="a.id">{{ a.name }}</option> </select> <p>您選擇的名字的Id是:{{select}}</p> </div></template>js代碼
<script> export default { data(){ return{ select:'', arr:[ {id:'1',name:'html'}, {id:'2',name:'css'}, {id:'3',name:'js'}, ] } } }</script>拓展知識(shí):vue獲取id以及重定向路由方法
1.獲取ID的方法:
let orderId=this.$route.query.id;
2.路由重定向方法
this.$router.push(this.$route.query.redirect || '/login')
以上這篇vue操作下拉選擇器獲取選擇的數(shù)據(jù)的id方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持錯(cuò)新站長站。
新聞熱點(diǎn)
疑難解答
圖片精選