Skip to content

Commit c4f6e0c

Browse files
docs: update the API entries for mixins and extends (#1146)
* docs: update the API entries for mixins and extends * Update src/api/options-composition.md Co-authored-by: Ben Hong <[email protected]>
1 parent 29cf54c commit c4f6e0c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/api/options-composition.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010

1111
Mixin hooks are called in the order they are provided, and called before the component's own hooks.
1212

13+
:::info
14+
In Vue 2, mixins were the primary mechanism for creating reusable chunks of component logic. While mixins continue to be supported in Vue 3, the [Composition API](/guide/composition-api-introduction.html) is now the preferred approach for code reuse between components.
15+
:::
16+
1317
- **Example:**
1418

1519
```js
1620
const mixin = {
17-
created: function() {
21+
created() {
1822
console.log(1)
1923
}
2024
}
@@ -34,20 +38,23 @@
3438

3539
## extends
3640

37-
- **Type:** `Object | Function`
41+
- **Type:** `Object`
3842

3943
- **Details:**
4044

41-
Allows declaratively extending another component (could be either a plain options object or a constructor). This is primarily intended to make it easier to extend between single file components.
45+
Allows one component to extend another, inheriting its component options.
46+
47+
From an implementation perspective, `extends` is almost identical to `mixins`. The component specified by `extends` will be treated as though it were the first mixin.
48+
49+
However, `extends` and `mixins` express different intents. The `mixins` option is primarily used to compose chunks of functionality, whereas `extends` is primarily concerned with inheritance.
4250

43-
This is similar to `mixins`.
51+
As with `mixins`, any options will be merged using the relevant merge strategy.
4452

4553
- **Example:**
4654

4755
```js
4856
const CompA = { ... }
4957

50-
// extend CompA without having to call `Vue.extend` on either
5158
const CompB = {
5259
extends: CompA,
5360
...

0 commit comments

Comments
 (0)