Skip to content

Add 2 examples on how to use injection in props/data #800

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

Merged
merged 1 commit into from
Mar 3, 2017
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
28 changes: 28 additions & 0 deletions src/v2/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,34 @@ All lifecycle hooks automatically have their `this` context bound to the instanc
}
```

> 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.

Using an injected value as the default for a prop:
```js
const Child = {
inject: ['foo'],
props: {
bar: {
default () {
return this.foo
}
}
}
}
```

Using an injected value as data entry:
```js
const Child = {
inject: ['foo'],
data () {
return {
bar: this.foo
}
}
}
```

## Options / Misc

### name
Expand Down