iView的select组件API文档中,没有提供这个功能,但是打印组件对象,可以看到里面有很多API文档中没有提到的function。toggleMenu()用来展开选择器菜单,hideMenu()用来隐藏选择器菜单。
template:在Select组件中,设置ref,用来在触发的事件中确认元素。使用@mouseenter.native和@mouseleave.native来触发鼠标移入、移出的事件。
<Select v-model="xxx" @mouseenter.native="autoShow('type')"
@mouseleave.native="autoHide('type')" ref="type">
<Option value="-1">全部设备</Option>
<Option v-for="item in list" :value="item.id" :key="item.id">{{ item.name }}</Option>
</Select>
js:触发事件时,接收参数,调用对应的元素方法。
autoShow(ref) {
this.$refs[ref].toggleMenu();
},
autoHide(ref) {
this.$refs[ref].hideMenu();
},