a-select v-modelvalue=yncfcfDoctor show-search filter-option=changeOption style=width 150px a-select-option v-for=item in doctors key=itempym value=itemid itememployname a-select-option
在Vue 3的setup()函数中,你可以使用watch()函数来监听a-select的改变,并将结果输出给控制台。下面是一个示例代码:
<template>
<a-select v-model:value="selectedDoctor" show-search :filter-option="changeOption" style="width: 150px">
<a-select-option v-for="item in doctors" :key="item.pym" :value="item.id">{{ item.employname }}</a-select-option>
</a-select>
</template>
<script>
import { ref, watch } from 'vue';
export default {
setup() {
const selectedDoctor = ref(null);
const doctors = ref([
{ id: 1, employname: 'Doctor 1' },
{ id: 2, employname: 'Doctor 2' },
{ id: 3, employname: 'Doctor 3' },
]);
// 监听 selectedDoctor 的改变
watch(selectedDoctor, (newVal) => {
console.log('Selected Doctor:', newVal);
});
return {
selectedDoctor,
doctors,
};
},
};
</script>
在上面的示例中,我们创建了一个selectedDoctor的响应式引用,用于存储用户选择的医生。然后,我们使用watch()函数来监听selectedDoctor的变化,并在变化时将结果输出给控制台
原文地址: https://www.cveoy.top/t/topic/iQEb 著作权归作者所有。请勿转载和采集!