Skip to content

Commit a861494

Browse files
author
ntepluhina
committed
feat: started reactive provide/inject
1 parent d41a9c0 commit a861494

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/guide/component-provide-inject.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Provide / Inject
1+
# Provide / inject
22

33
> This page assumes you've already read the [Components Basics](components.md). Read that first if you are new to components.
44
@@ -93,3 +93,16 @@ In fact, you can think of dependency injection as sort of “long-range props”
9393
- descendant components don’t need to know where injected properties are coming from
9494

9595
## Working with reactivity
96+
97+
In the example above, if we change the list of `todos`, this change won't be reflected in the injected `foo` property. This is because `provide/inject` bindings are _not_ reactive by default. We can change this behavior with passing a `ref` property or `reactive` object to `provide`. In our case, if we want to react to changes in ancestor component, we need to assign a Composition API `computed` property to our provided `foo`:
98+
99+
```js
100+
app.component('todo-list', {
101+
// ...
102+
provide() {
103+
return {
104+
foo: Vue.computed(() => this.todos.length)
105+
}
106+
}
107+
})
108+
```

0 commit comments

Comments
 (0)