Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: 补充选项式api options.shallowReactivePattern 文档 #1820

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs-vitepress/api/optional-api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
# 选项式 API

### options.shallowReactivePattern
- **类型:** `RegExp`
- **详细:**

取消data/properties内数据的深度响应。

适用于每次更新均为整体的更新而非局部少量数据更新的大型数据,可减少掉对应属性“数据响应初始化”以及“diff比较”两个阶段的耗时

```html
<!-- child -->
<script>
createComponent({
properties: {
bigPropData: Object
},
data: {
// 这个是视图上需要用到的大数据
bigData: { a: 0 }
},
options: {
// 配置具体哪些data或者properties需要忽略响应
shallowReactivePattern: /bigData|bigPropData/
},
methods: {
foo() {
this.bigData = { a: 1 } // 可触发视图更新
},
bar() {
this.bigData.a = 2 // 不可触发视图更新
}
}
})
</script>

<!-- perant -->
<template>
<child bigPropData="{{parentBigData}}"/>
</template>
<script>
createComponent({
data: {
parentBigData: []
},
options: {
shallowReactivePattern: /parentBigData/ // 父组件中传入的data也需要开启shallowReactive
}
})
</script>
```

> 注意

### onAppInit
- **类型:** `Function`
- **详细:**
Expand Down
Loading