【问题标题】:V-autocomplete @blur no valueV-autocomplete @blur 没有价值
【发布时间】:2021-11-17 09:41:22
【问题描述】:

我想在触发模糊事件时在 v-autocomplete 中获取所选值的值。值 $event.target.value 始终设置为空字符串。我通过拆分 parentElement 的 innerText 找到了一种解决方法:

var value = $event.parentElement.innerText;
value = value ? value.split('\n') : [];

值得注意的是,只有当我在 v-autocomplete 中设置了 multiple 属性时才会发生这种情况:

<template v-slot:item.fieldName="{ item }">
  <v-autocomplete
    multiple
    small-chips
    :value="item.fieldName"
    :items="items"
    color="primary"
    @blur="updateItem(item, $event.target.value, 'fieldName')">
  </v-autocomplete>
</template>

我找不到有关此问题的任何信息。我不应该这样使用这个输入吗?

【问题讨论】:

    标签: javascript vue.js vuetify.js


    【解决方案1】:

    您是否尝试将它与 v-model 一起使用?这里应该使用双向绑定,所以我们不需要使用 $event.target.value 手动获取项目。

    <v-autocomplete
                v-model="values"
                :items="items"
                dense
                chips
                small-chips
                label="Solo"
                multiple
                solo
              ></v-autocomplete>
    

    所以您应该能够直接从 values 字段中获取数据。以供参考: https://github.com/vuetifyjs/vuetify/blob/master/packages/docs/src/examples/v-autocomplete/prop-dense.vue

    【讨论】:

    • 不幸的是,此解决方案不可行,因为在每次更改后,回调都会调用后端 API 来验证输入,进而在本地更新状态。因此,在用户完成更改后仅触发一次回调是原始的。
    • 你什么时候调用这个api可以请你分享一个例子。也许尝试使用 debounce 或在 @input 事件上发送 API 调用?
    • 该api在updateItem方法中被调用。 @blur="updateItem(item, $event.target.value, 'fieldName')"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    相关资源
    最近更新 更多