vue.js - 带有 VueJS 自动完成的元素 UI:避免突变 A 道具(Vue 警告)
问题描述
我对 VueJS 和 Element UI 有一个大问题https://element.eleme.io/#/en-US/component/input#autocomplete-attributes 我使用自动完成组件,我希望我点击输入(onFocus事件),我的建议重新出现
<el-autocomplete
id="inputID"
name="inputName"
class="inputClass"
v-model="inputModel"
:fetch-suggestions="querySearchInput"
placeholder= "Select an Input"
ref="inputReference"
value-key="id"
v-loading="inputLoader"
:value="inputValue"
@select="onChangeInput"
@focus="onFocusInput"
@clear="onClearInput"
clearable
>
<!-- Slot : Override Component Suggestions -->
<template slot-scope="{item}" v-if="item.id">
{{ item.id }} - {{ item.name }}
</template>
</el-autocomplete>
在我使用的 onFocus 或 onClear 上:
this.inputModel = "";
this.inputValue = ""
但这并没有重置我的建议..:/我唯一的方法是使用:
this.$refs.inputReference.value = "";
但这不是最佳实践我有一条消息:“vue.esm.js?efeb:591 [Vue 警告]:避免直接改变 prop,因为每当父组件重新渲染时,该值都会被覆盖。相反,使用数据或基于道具值的计算属性。道具正在变异:“值”“
我在组件上使用 :value 和 v-model,因为我有一个 ID,但我用 i18n 显示标签,这并不重要
非常感谢你
我认为这是因为 AutoComplete 组件包含一个 InputComponent,而我不是 VueJS 上的级联道具的专业人士。
谢谢。
解决方案
就像它说的那样做。不要改变道具。如果需要从 props 中更改某些日期,请将其保存到本地组件数据并进行修改
props: {
foo: {
type: number,
requred: true
}
},
...
data () {
return {
localFoo: this.foo
}
}
推荐阅读
- java - 如何只允许用户输入 az 的输入并使用 if 语句提示正确的输入
- python - 创建一个列表 t,如果它包含“t”,则仅保存运动员的姓名。如果不包含字母“t”,则将运动员姓名保存到其他列表中
- python - Python3 打印语句未在命令行上显示任何输出
- python-3.x - 直接运行与 pytests 时的 Python3 导入问题
- powerbi - PowerBI中的多对多关系按日期
- android - 如何使用 Flutter 应用程序从文件管理器打开(音频)文件
- c# - 使用 System.Web.Optimization 捆绑,如何访问构建捆绑的结果?
- python - 在不使用 .py 扩展名的情况下从不同的文件夹导入 python
- matplotlib - 在 matplotlib 中以物理坐标定位轴
- javascript - onload 函数只显示一个结果(我认为是列表中的最后一项)x 次