Javascript 大量对象的Vuetify数据表速度较慢
我有一个具有计算属性的自定义对象Javascript 大量对象的Vuetify数据表速度较慢,javascript,vue.js,vuetify.js,Javascript,Vue.js,Vuetify.js,我有一个具有计算属性的自定义对象 class MyObject { get someComputedProp() { // expensive computation based on some other props } } 以及一个vuetify数据表,其中包含约500个对象 <v-data-table :headers="headers" :items="myObjects" :search="search" > <template sl
class MyObject {
get someComputedProp() {
// expensive computation based on some other props
}
}
以及一个vuetify数据表,其中包含约500个对象
<v-data-table
:headers="headers"
:items="myObjects"
:search="search"
>
<template slot="items" slot-scope="{ item }">
<td>{{ item.someComputedProp }}</td>
...
这将使4个呼叫中的3个便宜,但在另一个vue上,我需要计算的道具进行实时更新,因为它所依赖的道具已更新。现在我被困在做这种傻事
set propThatComputedPropDependsOn (value) {
this._cachedComputedProp = null
this._propThatComputedPropDependsOn = value
}
嗯,也许这对其他人有用:
// in constructor
this.cacheProps = true
get someComputedProp() {
if (!this._cachedComputedProp || !this.cacheProps)
this._cachedComputedProp = // expensive computation based on some other props
}
return this._cachedComputedProp
}
cacheProps
设置为false
// in constructor
this.cacheProps = true
get someComputedProp() {
if (!this._cachedComputedProp || !this.cacheProps)
this._cachedComputedProp = // expensive computation based on some other props
}
return this._cachedComputedProp
}