From c40de74a7d64cf411a5f07f89140d247af3b2877 Mon Sep 17 00:00:00 2001 From: Raymond Rutjes Date: Fri, 3 Mar 2017 11:12:46 +0100 Subject: [PATCH] Add 2 examples on how to use injection in props/data Relates to #5067, #5075 --- src/v2/api/index.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/v2/api/index.md b/src/v2/api/index.md index 4eceeebf2e..90247637dc 100644 --- a/src/v2/api/index.md +++ b/src/v2/api/index.md @@ -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