Я создаю относительно большое веб-приложение с Nuxt JS (но этот вопрос касается Vue).
У меня есть домашняя страница, которая содержит много панелей, визуализированных с помощью v-for.
Отображаемый список является результатом вычисляемого свойства, которое опирается на множество значений данных:
services() {
console.log('services')
const base = [
{
header: 'Novità',
id: 'circolari',
color: '#1A2B63',
sync: this.sync.circolare,
component: () => import('~/components/one_use_component/circolari_list'),
props: {
error: this.error.circolare,
isShowingCircolari: this.isShowingCircolari && this.showCircolari
}
},
{
id: 'orario',
color: '#FD4F19',
sync: null,
component: () => import('~/components/one_use_component/orario_today'),
props: {
today: this.today
}
},
{
id: 'sondaggi',
btn: this.$auth.loggedIn && this.$auth.user.scope > 1 ? 'Sondaggi' : false,
color: '#556080',
sync: this.sync.sondaggi,
component: () => import('~/components/one_use_component/sondaggi_available'),
add: this.$auth.loggedIn && this.$auth.user.scope > 1 ? '/sondaggi/admin/add' : false,
props: {
error: this.error.sondaggi
}
},
{
id: 'treni',
btn: false,
color: '#BD392A',
sync: this.sync.treni,
modify: '/treni',
component: () => import('~/components/one_use_component/my_train'),
props: {
error: this.error.treni,
isShowingAndata: this.isShowingAndata
}
},
{
id: 'giornalino',
color: '#B0C4D9',
sync: this.sync.giornalino,
component: () => import('~/components/one_use_component/last_articles'),
props: {
error: this.error.giornalino
}
}
]
return this.$auth.loggedIn && this.$auth.user.isValidated
? base.filter(s => !(this.$store.state.general.services.unused.indexOf(s.id) !== -1)).sort((a, b) => this.$store.state.general.services.order.indexOf(a.id) - this.$store.state.general.services.order.indexOf(b.id))
: base.slice(0, 1)
}
На этапе загрузки я вызываю методы, которые обновляют syn c и объект ошибки, который заставляет все вычисленное свойство запускаться несколько раз (около 6-7 раз) за загрузку. Как я могу сделать это более эффективным? И наличие import
внутри может вызвать утечку памяти или что-то еще?