google-chrome - Vue.js 中 Chrome 和 Datalist 的性能问题

标签 google-chrome vue.js html-datalist

我在使用 Google Chrome(最新版本:83.0.4103.97)的 vue.js 中的 datalist 存在性能问题。
我不得不说我几个月前开始学习 Vue.js 所以我还是个菜鸟。
使用 Firefox 一切正常,数据列表和过滤立即生效。
使用 Chrome 一切都很慢......我在输入字段中输入,字母显示非常缓慢(或一次全部显示),我必须等待很多秒钟才能应用过滤器。在此之后,我必须在元素上多次单击以填充该字段。
以下是浏览器行为和部分代码的视频。
火狐:https://streamable.com/vj4rbb
Chrome :https://streamable.com/2sikq5
组件代码:

<b-input-group size="sm" v-if="menuEditState">
  <b-form-input
    :list="`mealDish${meal.id}`"
    :id="`input${meal.id}`"
    placeholder="Selectionner un plat"
    v-model="name"
    :class="{'is-invalid': $v.name.$anyError}"
  />
  <datalist :id="`mealDish${meal.id}`">
    <option v-for="dish in activeDishesByType" :value="`${dish.name} (${dish.humanType})`" :data-value="dish.id"></option>
  </datalist>
  
  <b-input-group-append>
    <b-button variant="primary" @click="onClick" :disabled="loading">
      <i :class="loading ? 'fa fa-spin fa-circle-notch' : 'fa fa-plus'" />
    </b-button>
  </b-input-group-append>
</b-input-group>
和脚本
  computed: {
...mapGetters({
  activeDishesByType: 'activeDishesByType',
}),
getter 基于 getter 中的 Vuex 状态排序(如果我使用没有 getter 排序的状态,我有相同的行为)。
我知道 chrome 开发工具中有一个性能监视器,我试图找到一些可以帮助我解决这个问题的东西,但我不知道在哪里搜索所有这些信息。
谢谢你的帮助。
罗曼。

最佳答案

好的,我终于找到了在 Chrome 中导致如此多性能问题的元素。
它在数据列表选项中的值...
所以我设法在数据列表中只使用 data-* 和 text 。
请不要犹豫,改进这一点或添加评论。
数据列表上不再有“值(value)”:

 <b-input-group size="sm">
  <b-form-input
    :list="`mealDish${meal.id}`"
    :id="`input${meal.id}`"
    placeholder="Selectionner un plat"
    v-model="name"
  />
  <datalist :id="`mealDish${meal.id}`">
    <option v-for="dish in activeDishesByType" :data-value="dish.id">{{
      `${dish.name} (${dish.humanType})`
    }}</option>
  </datalist>
  
  <b-input-group-append>
    <b-button variant="primary" @click="onClick" :disabled="loading">
      <i :class="loading ? 'fa fa-spin fa-circle-notch' : 'fa fa-plus'" />
    </b-button>
  </b-input-group-append>
</b-input-group>
并在 datalist 选项中搜索以恢复我的数据值:
  // Get the selected/typed value
  const shownVal = document.getElementById(`input${this.meal.id}`).value;
  const datalist = document.querySelector(`#mealDish${this.meal.id}`);
  // Find the option in the list and get the data-value (id)
  let dishId = null;
  for (var i = 0; i < datalist.options.length; i++) {
    if (datalist.options[i].text === shownVal) {
      dishId = datalist.options[i].dataset.value;
      break;
    }
  }

关于google-chrome - Vue.js 中 Chrome 和 Datalist 的性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62213505/

相关文章:

javascript - v-on :click does not work (vue. js)

typescript - 使用 typescript 时如何添加自定义扩展

javascript - HTML5 DataList 是否有 SelectedIndex?

javascript - innerHTML 不适用于 IE 中的 <datalist> HTML5 元素

javascript - 单击 HTML5 数据列表选项时执行操作

javascript - Chrome 的 JavaScript 控制台是否懒惰评估对象?

AJAX 请求和连接超时 : Chrome doesn't timeout after over 15 hours, 但 IE 呢?

html - Chrome 中隐藏文字之谜

css - 在 Chrome 的用户代理样式表中,为什么使用 "-webkit-margin-before"等而不是 "margin-top"等?

javascript - 更新单元测试的 vue 组件实例中的 Prop