Skip to content

Commit 018a58f

Browse files
Mister-Hopeantfu
andauthored
docs: update readme (#560)
Co-authored-by: Anthony Fu <[email protected]>
1 parent 35f8fec commit 018a58f

File tree

2 files changed

+77
-10
lines changed

2 files changed

+77
-10
lines changed

README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ Vue 2 plugin for **Composition API**
66
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/vuejs/composition-api/Build%20&%20Test)](https://github.com/vuejs/composition-api/actions?query=workflow%3A%22Build+%26+Test%22)
77
[![Minzipped size](https://badgen.net/bundlephobia/minzip/@vue/composition-api)](https://bundlephobia.com/result?p=@vue/composition-api)
88

9-
10-
119
English | [中文](./README.zh-CN.md)[**Composition API Docs**](https://composition-api.vuejs.org/)
1210

1311
## Installation
@@ -181,7 +179,7 @@ a.list[1].count === 1 // true
181179

182180
<details>
183181
<summary>
184-
⚠️ `set` workaround for adding new reactive properties
182+
⚠️ <code>set</code> workaround for adding new reactive properties
185183
</summary>
186184

187185
> ⚠️ Warning: `set` does NOT exist in Vue 3. We provide it as a workaround here, due to the limitation of [Vue 2.x reactivity system](https://vuejs.org/v2/guide/reactivity.html#For-Objects). In Vue 2, you will need to call `set` to track new keys on an `object`(similar to `Vue.set` but for `reactive objects` created by the Composition API). In Vue 3, you can just assign them like normal objects.
@@ -197,7 +195,6 @@ const a = reactive({
197195
set(a, 'bar', 1)
198196
```
199197

200-
201198
</details>
202199

203200
### Template Refs
@@ -417,6 +414,7 @@ app2.component('Bar', Bar) // equivalent to Vue.use('Bar', Bar)
417414
</details>
418415

419416
### `props`
417+
420418
<details>
421419
<summary>
422420
⚠️ <code>toRefs(props.foo.bar)</code> will incorrectly warn when acessing nested levels of props.
@@ -427,8 +425,8 @@ app2.component('Bar', Bar) // equivalent to Vue.use('Bar', Bar)
427425
defineComponent({
428426
setup(props) {
429427
const { bar } = toRefs(props.foo) // it will `warn`
430-
431-
// use this instead
428+
429+
// use this instead
432430
const { foo } = toRefs(props)
433431
const a = foo.value.bar
434432
}
@@ -437,8 +435,6 @@ defineComponent({
437435

438436
</details>
439437

440-
441-
442438
### Missing APIs
443439

444440
The following APIs introduced in Vue 3 are not available in this plugin.
@@ -469,6 +465,31 @@ export default {
469465

470466
</details>
471467

468+
### `emit` Options
469+
470+
<details>
471+
<summary>
472+
❌ <code>emit</code> option is provided in type-level only, in order to align with Vue 3's type interface. Does NOT have actual effects on the code.
473+
</summary>
474+
475+
```ts
476+
defineComponent({
477+
emit: {
478+
// has no effects
479+
submit: (eventOption) => {
480+
if (...) {
481+
return true
482+
} else {
483+
console.warn('Invalid submit event payload!')
484+
return false
485+
}
486+
}
487+
}
488+
})
489+
```
490+
491+
</details>
492+
472493
### Performance Impact
473494

474495
Due the the limitation of Vue2's public API. `@vue/composition-api` inevitably introduced some extract costs. It shouldn't bother you unless in extreme environments.

README.zh-CN.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,9 @@ b.list[1].count === 1 // true
175175

176176
</details>
177177

178-
179178
<details>
180179
<summary>
181-
⚠️ `set` 添加响应式属性变通方案
180+
⚠️ <code>set</code> 添加响应式属性变通方案
182181
</summary>
183182

184183
> ⚠️ 警告: `set` 并非 `Vue 3.0` 的一部分。由于 [Vue 2.x 响应式系统的限制](https://vuejs.org/v2/guide/reactivity.html#For-Objects),我们在插件中提供该 API 作为添加响应式属性的一个变通方案。在 Vue 3 中,你只需要直接为属性赋值即可。
@@ -393,6 +392,28 @@ watch(
393392
394393
</details>
395394

395+
### `props`
396+
397+
<details>
398+
<summary>
399+
⚠️ 当使用 <code>toRefs</code> 访问深层属性对象 (如 <code>toRefs(props.foo.bar)</code> 时将会得到不正确的警告。
400+
⚠️ <code>isReactive(props.foo.bar)</code> 将会返回 false。
401+
</summary>
402+
403+
```ts
404+
defineComponent({
405+
setup(props) {
406+
const { bar } = toRefs(props.foo) // it will `warn`
407+
408+
// use this instead
409+
const { foo } = toRefs(props)
410+
const a = foo.value.bar
411+
}
412+
})
413+
```
414+
415+
</details>
416+
396417
### 缺失的 API
397418

398419
以下在 Vue 3 新引入的 API ,在本插件中暂不适用:
@@ -423,6 +444,31 @@ export default {
423444

424445
</details>
425446

447+
### `emit` 选项
448+
449+
<details>
450+
<summary>
451+
❌ <code>emit</code> 仅因在类型定义中对齐 Vue3 的选项而提供,<b>不会</b>有任何效果。
452+
</summary>
453+
454+
```ts
455+
defineComponent({
456+
emit: {
457+
// 无效
458+
submit: (eventOption) => {
459+
if (...) {
460+
return true
461+
} else {
462+
console.warn('Invalid submit event payload!')
463+
return false
464+
}
465+
}
466+
}
467+
})
468+
```
469+
470+
</details>
471+
426472
### 性能影响
427473

428474
由于 Vue 2 的公共 API 的限制,`@vue/composition-api` 不可避免地引入了额外的性能开销。除非在极端情况下,否则这并不会对你造成影响。

0 commit comments

Comments
 (0)