el-autocomplete change不生效
时间: 2023-08-26 11:07:51 浏览: 241
根据引用\[1\],el-autocomplete是一个HTML组件,用于创建一个自动完成的输入框。根据引用\[2\],可以通过在el-autocomplete上添加属性popper-append-to-body="false"来解决change事件不生效的问题。这个属性的作用是将渲染后的元素放入#app元素中。代码示例如下:
```
<el-autocomplete v-model="state" :fetch-suggestions="querySearchAsync" placeholder="请输入内容" style="width: 300px" :popper-append-to-body="false"></el-autocomplete>
```
然而,根据引用\[3\]的描述,将popper-append-to-body属性设置为false解决了change事件不生效的问题,但是导致了原本设置的下拉框的内边距失效。为了解决这个问题,可以使用popper-class属性。popper-class属性用于设置下拉列表的类名。在组件中加入popper-class="acc-search",可以将自定义的CSS样式应用于下拉列表。代码示例如下:
```
<el-autocomplete class="voucher-subject-input" :ref="'inputcredit_2_'+index" :popper-append-to-body="true" popper-class="acc-search" :class="{ 'subject-opacity': voucher.items\[index\].showText }" v-model="voucher.items\[index\].subjectName" value-key="name" :fetch-suggestions="querySearch" :highlight-first-item="true" @blur="handleSelectBlur(voucher.items\[index\],index)" @select="handleSelectSubject($event,index)" @focus="handleFocusSubject($event,index)">
<template slot-scope="{ item }">
<el-button v-if="item.is_add" type="primary" plain style="width: 100%;position: absolute;bottom: 0px;left: 0px;" class="add-button" @click="accAddBtn()">添加</el-button>
</template>
</el-autocomplete>
```
通过以上的修改,你应该能够解决el-autocomplete change事件不生效的问题,并且保持下拉框的内边距生效。
#### 引用[.reference_title]
- *1* [vue组件之el-tree、el-select、el-autocomplete、el-table篇](https://blog.csdn.net/qq_43977829/article/details/124166369)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [el-autocomplete修改默认样式 不生效问题(已解决)](https://blog.csdn.net/Maxueyingying/article/details/121373387)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [【关于Element UI中el-autocomplete组件】二、el-autocomplete组件解决@blur与@select事件冲突](https://blog.csdn.net/XujiRe/article/details/125413153)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文