Antd vue 点击下拉框会偏移然后闪烁

文章讲述了在使用ANTD库时,下拉框和日期选择器的动画可能导致观感不佳,通过关闭动画效果可以解决闪动和位置调整问题,以提升用户界面的流畅性。

ANTD 下拉框点开都会有动画效果,所以会闪一下,再缩放自适应下,位置会闪一下缩放前位置再定位正确位置影响观感,所以关闭动画即可。

/* 日期选择框动画样式关闭 */
.ant-calendar-picker-container.slide-up-appear.slide-up-appear-active.ant-calendar-picker-container-placement-bottomLeft, .ant-calendar-picker-container.slide-up-enter.slide-up-enter-active.ant-calendar-picker-container-placement-bottomLeft {
  -webkit-animation-name: unset;
  animation-name: unset;
  -webkit-animation-duration: .05s;
  animation-duration: .05s;
}

.ant-calendar-picker-container.slide-up-appear.slide-up-appear-active.ant-calendar-picker-container-placement-topLeft, .ant-calendar-picker-container.slide-up-enter.slide-up-enter-active.ant-calendar-picker-container-placement-topLeft {
  -webkit-animation-name: unset;
  animation-name: unset;
  -webkit-animation-duration: .05s;
  animation-duration: .05s;
}

.ant-calendar-picker-container.slide-up-leave.slide-up-leave-active.ant-calendar-picker-container-placement-bottomLeft {
  -webkit-animation-name: unset;
  animation-name: unset;
  -webkit-animation-duration: .05s;
  animation-duration: .05s;
}

.ant-calendar-picker-container.slide-up-leave.slide-up-leave-active.ant-calendar-picker-container-placement-topLeft {
  -webkit-animation-name: unset;
  animation-name: unset;
  -webkit-animation-duration: .05s;
  animation-duration: .05s;
}
/* 滚动条动画样式关闭 */
.ant-select-dropdown.slide-up-appear.slide-up-appear-active.ant-select-dropdown-placement-bottomLeft, .ant-select-dropdown.slide-up-enter.slide-up-enter-active.ant-select-dropdown-placement-bottomLeft {
  -webkit-animation-name: unset;
  animation-name: unset;
  -webkit-animation-duration: .05s;
  animation-duration: .05s;
}

.ant-select-dropdown.slide-up-appear.slide-up-appear-active.ant-select-dropdown-placement-topLeft, .ant-select-dropdown.slide-up-enter.slide-up-enter-active.ant-select-dropdown-placement-topLeft {
  -webkit-animation-name: unset;
  animation-name: unset;
  -webkit-animation-duration: .05s;
  animation-duration: .05s;
}

.ant-select-dropdown.slide-up-leave.slide-up-leave-active.ant-select-dropdown-placement-bottomLeft {
  -webkit-animation-name: unset;
  animation-name: unset;
  -webkit-animation-duration: .05s;
  animation-duration: .05s;
}

.ant-select-dropdown.slide-up-leave.slide-up-leave-active.ant-select-dropdown-placement-topLeft {
  -webkit-animation-name: unset;
  animation-name: unset;
  -webkit-animation-duration: .05s;
  animation-duration: .05s;
}

Vue2 中使用 Ant Design Vue 下拉框搜索到值后不展示,可尝试以下解决办法: ### 1. 自定义过滤规则 使用 `filter-option` 属性自定义选项的过滤规则。当用户在下拉框中输入内容进行搜索时,该属性可指定一个方法来根据输入内容过滤选项。以下是示例代码: ```vue <template> <a-select v-decorator="['unit']" option-filter-prop="children" :show-search="true" :allow-clear="true" style="width:60%" :filter-option="filterOption" @change="getRoleList" placeholder="请选择关联单位" > <a-select-option v-for="item in deptIdList" :key="item.id" :value="item.unitCode + ';' + item.deptName"> {{ item.unitCode + ";" + item.deptName }} </a-select-option> </a-select> </template> <script> export default { data() { return { deptIdList: [ // 数据列表 ] }; }, methods: { filterOption(input, option) { return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0; }, getRoleList() { // 处理选择变化的逻辑 } } }; </script> ``` ### 2. 设置 `optionFilterProp` 属性 将 `optionFilterProp` 设置为合适的值,如 `label`,并在 `a-select-option` 中设置 `:label` 自定义属性。示例代码如下: ```vue <template> <a-select showSearch allowClear optionFilterProp="label" placeholder="请选择选项" style="width: 120px; margin-right: 16px" > <a-select-option v-for="item in options" :key="item.code" :value="item.id" :label="item.name"> {{ item.name }} </a-select-option> </a-select> </template> <script> export default { data() { return { options: [ // 选项数据 ] }; } }; </script> ``` ### 3. 处理下拉框在弹窗中的显示问题 若下拉框在弹窗中使用导致选项显示不出来,可通过 `:getPopupContainer` 属性指定下拉框的挂载容器。示例代码如下: ```vue <template> <a-select v-decorator="['unit']" option-filter-prop="children" :show-search="true" :allow-clear="true" style="width:60%" :getPopupContainer="triggerNode => { return triggerNode.parentNode || document.body; }" @change="getRoleList" placeholder="请选择关联单位" > <a-select-option v-for="item in deptIdList" :key="item.id" :value="item.unitCode + ';' + item.deptName"> {{ item.unitCode + ";" + item.deptName }} </a-select-option> </a-select> </template> <script> export default { data() { return { deptIdList: [ // 数据列表 ] }; }, methods: { getRoleList() { // 处理选择变化的逻辑 } } }; </script> ```
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值