打算做點擊按鈕后清空select選項,但是發現直接給組件綁定值賦值是不行的。
研究了一下,以下方法是element-plus清空select選項的可行方法。
<el-time-select v-model="choiceTime" ref="choiceTimeRef" start="08:00" step="00:30" end="22:00" placeholder="選擇時間" > </el-time-select> const choiceTime = ref(); const choiceTimeRef = ref(); function(){ if(/**條件和函數自己腦補吧**/){
choiceTime.value = undefined //這個方法不行
choiceTimeRef.value.value = undefined; //這樣才是正確方法
} }
當然choiceTime.value也得清空,不然如果下一次有人沒選擇日期,而直接點的提交,就會獲取到你上次選擇到的值,雖然這個值在dom上被清空了看不到了。