performance - vuetify 列表性能问题

标签 performance cordova vue.js vuetify.js

我有一个简单的 json 数组,其中包含这样的对象

{
    "kb:esid": "779256bf333d2d11abb52e39aafff20d",
    "kb:station": "Disco935 New York's Jammer",
    "kb:description": "Playing The 70's 80's 90's Disco And Beyond",
    "kb:station_url_record": {
        "kb:url_no": "1",
        "kb:url": "http://localhost/stream",
        "kb:status_code": "A",
        "kb:bandwidth_kbps": "128",
        "kb:url_strength": "9"
    }
}

我在 codrova 项目上使用 vuetify 来渲染列表。该列表由 3 行组成:站、描述和带宽。还有一个简单的组件可以将电台标记为收藏夹。

列表渲染大约需要 5 秒来渲染约 200 个元素。我使用的是有点旧的智能手机:2GB 内存、5.1 Android、~1.2 GHz CPU。

如何提高渲染速度?我尝试在 vuetify 中搜索无限列表,但没有任何内容。

谢谢。

最佳答案

Vue.js 加载起来有点重,但是您可以通过实现无限滚动组件来使用延迟初始化。有一个名为 vue-mugen-scroll 的已实现组件。它还具有 CDN link如果您需要快速测试。

只需将 getStations 方法替换为异步服务器调用即可完成。检查此代码片段以了解其工作原理。

let vm = new Vue({
  el: '#vue-instance',
  data: {
    stations: [],
    loading: false,
  },
  created() {
    this.getStations();
  },
  methods: {
    getStations() {
      for (let i = 0; i < 16; i++) {
        const count = this.stations.length + i;
        this.stations.push({
          esid: '779256bf333d2d11abb52e39aafff20d' + count,
          name: 'Station ' + count,
          description: 'Station Description ' + count,
          record: 'Station Record ' + count,
        });
      }
    },
  },
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e383b2b63233b292b20633d2d3c2122220e7e607c607b" rel="noreferrer noopener nofollow">[email protected]</a>/dist/vue-mugen-scroll.min.js"></script>
<div id="vue-instance" class="container">
  <div class="row">
    <div class="col-sm-6" v-for="(station, index) in stations">
      <div class="card m-4" style="width: 18rem;">
        <div class="card-body">
          <h3 class="card-title">{{ station.name }}</h3>
          <p>{{ station.esid }}</p>
          <p>{{ station.description }}</p>
          <p>{{ station.record }}</p>
        </div>
      </div>
    </div>
  </div>
  <mugen-scroll :handler="getStations" :should-handle="!loading">
    loading...
  </mugen-scroll>
</div>

关于performance - vuetify 列表性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54338341/

相关文章:

c# - Dictionary<> 中的条目是否有限制?

java - Proguard 返回错误代码 1 - 尝试使用 Proguard

javascript - 具有基于数组值的 3 向切换功能的 Vue 按钮

android - 是否需要关闭使用 window.openDatabase 打开的数据库?

javascript - 美元前缀 ($) 在 Vue.js 中是什么意思?

javascript - 如何从 vue js 中的选择中获取值和文本?

oop - 为什么是 "Properties that return arrays are prone to code inefficiencies"?

.net - 有什么方法可以提高 Automapper 的性能吗?

android - Cordova/Phonegap 的 InAppBrowser 插件——window.open 不在默认浏览器中打开链接

node.js - Cordova 3.5.0 FileTransfer + NodeJS(多部分/表单数据)上传问题