vue如何監(jiān)聽el-select選擇值的變化
更新時間:2022年04月07日 15:04:09 作者:*且聽風(fēng)吟
這篇文章主要介紹了vue如何監(jiān)聽el-select選擇值的變化,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
監(jiān)聽el-select選擇值的變化
最近項目中需要用到監(jiān)聽 el-select 選擇值的改變
方法很簡單@change就可以實現(xiàn)
<el-select clearable
? ? ? ? ? ? ? ? ? ? ? ?v-model="formData.stationId"
? ? ? ? ? ? ? ? ? ? ? ?@change="currStationChange"
? ? ? ? ? ? ? ? ? ? ? ?:placeholder="$t('deviceManage.device.dlg.stationId')">
? ? ? ? ? ? ? <el-option v-for="item in stationOption"
? ? ? ? ? ? ? ? ? ? ? ? ?:key="item.value"
? ? ? ? ? ? ? ? ? ? ? ? ?:label="item.label"
? ? ? ? ? ? ? ? ? ? ? ? ?:value="item.value">
? ? ? ? ? ? ? </el-option>
</el-select>@change綁定了currStationChange
如果el-select選中的值發(fā)生變化,就會觸發(fā)currStationChange事件:
currStationChange(val) {
? ? ? console.log('currStationChange', val)
? ? ? if (val) {
? ? ? ? this.queryUnit(val)
? ? ? } else {
? ? ? ? // 所屬廠站沒有值,清空操作單元的值
? ? ? ? this.formData.unitId = null
? ? ? ? // 所屬廠站沒有值,清空操作單元下拉框選項
? ? ? ? this.unitTree = []
? ? ? }
}el-select將選中的值傳遞到需要的位置
方法一
<el-form-item label="選擇員工">
? ? ? ? ?<el-select v-model="deptPersonValue" @change="changeDeptValue">
? ? ? ? ? ? ? ? <el-option v-for="item in employeeList" :key="item.employeeId" ? ? ? ? ? ? ? ? ? ? ? ? :label="item.name" :value="item.employeeId">
? ? ? ? ? ? ? ? </el-option>
? ? ? ? </el-select>
?</el-form-item>
<p style="font-size:28px; margin-top:40px">{undefined{deptPersonName}}</p>changeDeptValue(setval) {undefined
? ? ? ? ?console.log(setval)
? ? ? ? let arr = this.employeeList.filter(item => {undefined
? ? ? ? ? return item.employeeId == this.deptPersonValue
? ? ? ? //邏輯判斷
? ? ? ?this.deptPersonName = arr.length == 0 ? '張靜' : arr[0].name
? ? ? ? this.$nextTick(() => {undefined
? ? ? ? //在這里處理echars圖片資源使用v-show或者v-if有些數(shù)據(jù)無法顯示的問題(在觸發(fā)事件 ? ? ? ? ? ?中需要重新初始化)
? ? ? ? ? this.roundChartFn()
? ? ? ? })
? ? ? }
? ? },方法二
此方法默認選擇第一天數(shù)據(jù)時會顯示第一條數(shù)據(jù)的id,目前自己還沒有解決
<el-form-item label="選擇員工">
? ? ? ? ?<el-select v-model="deptPersonValue" @change="changeDeptValue"
? ? ? ? ? ? ? ? ?value-key="value">
? ? ? ? ? ? ? ? <el-option v-for="item in employeeList" :key="item.employeeId" ? ? ? ? ? ? ? ? ? ? ? ? :label="item.name" :value="item">
? ? ? ? ? ? ? ? </el-option>
? ? ? ? </el-select>
?</el-form-item>
<p style="font-size:28px; margin-top:40px">{undefined{deptPersonName}}</p>changeDeptValue(setval) {undefined
? ? ? ? ?console.log(setval)
? ? ? ? //這里的name根據(jù)后端數(shù)據(jù)字段名來寫
? ? ? ? this.deptPersonName = this.deptPersonValue.name
? ? ? ? //邏輯判斷
? ? ? ?this.deptPersonName = arr.length == 0 ? '張靜' : arr[0].name
? ? ? }
? ? },以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue3使用vuex實現(xiàn)頁面實時更新數(shù)據(jù)實例教程(setup)
在前端開發(fā)中往往會遇到頁面需要實時刷新數(shù)據(jù)的情況,給用戶最新的數(shù)據(jù)展示,這篇文章主要給大家介紹了關(guān)于vue3使用vuex實現(xiàn)頁面實時更新數(shù)據(jù)(setup)的相關(guān)資料,需要的朋友可以參考下2022-09-09
Vue.js中用webpack合并打包多個組件并實現(xiàn)按需加載
對于現(xiàn)在前端插件的頻繁更新,我也是無力吐槽,但是既然入了前端的坑就得認嘛,所以多多少少要對組件化有點了解,下面這篇文章主要給大家介紹了在Vue.js中用webpack合并打包多個組件并實現(xiàn)按需加載的相關(guān)資料,需要的朋友可以參考下。2017-02-02
vue引入jquery時報錯 $ is not defined的問題及解決
這篇文章主要介紹了vue引入jquery時報錯 $ is not defined的問題及解決,具有很好的參考價值,希望對大家有所幫助。2022-09-09
vue3中$attrs的變化與inheritAttrs的使用詳解
$attrs現(xiàn)在包括class和style屬性。?也就是說在vue3中$listeners不存在了,vue2中$listeners是單獨存在的,在vue3?$attrs包括class和style屬性,?vue2中?$attrs?不包含class和style屬性,這篇文章主要介紹了vue3中$attrs的變化與inheritAttrs的使用?,需要的朋友可以參考下2022-10-10

