Akryum / Akryum/vue-9-perf-secrets

We may use computed property instead of child component splitting?

未关闭
#1 4 条评论 14 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Vue
星标
556
派生
78
PR 合并指标
30 天内没有已合并 PR

描述

First, thanks for the awesome Project!

In the `Child component splitting` demo,the root cause of the performance problem is that we use `heavy` function during render, it will also be called when the component render.

Instead of using child component splitting, can we use computed property? For example:
```


{{ heavy }}

export default {
props: ['number'],
computed: {
heavy () {
const n = 100000
let result = 0
for (let i = 0; i < n; i++) {
result += Math.sqrt(Math.cos(Math.sin(42)))
}
return result
}
}
}
```
Because create a child component will have some extra overhead, so computed property here is better ? Computed property will use cache if it's dependencies not change, and I think we should use computed property as much as possible other than method, unless in some special cases.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。