Skip to content

Commit 93f4f71

Browse files
committed
Add 2 examples on how to use injection in props/data
Relates to #5067, #5075
1 parent e87bc4c commit 93f4f71

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/v2/api/index.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,34 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
948948
}
949949
```
950950
951+
> The next 2 examples only work with Vue > 2.2.1. Below that version, injected values were resolved after the `props` and the `data` initialization.
952+
953+
Using an injected value as the default for a prop:
954+
```js
955+
const Child = {
956+
inject: ['foo'],
957+
props: {
958+
bar: {
959+
default () {
960+
return this.foo
961+
}
962+
}
963+
}
964+
}
965+
```
966+
967+
Using an injected value as data entry:
968+
```js
969+
const Child = {
970+
inject: ['foo'],
971+
data () {
972+
return {
973+
bar: this.foo
974+
}
975+
}
976+
}
977+
```
978+
951979
## Options / Misc
952980
953981
### name

0 commit comments

Comments
 (0)