Skip to content

Commit e86b8ee

Browse files
committed
update head management
1 parent 39e6e25 commit e86b8ee

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

en/head.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,9 @@
22

33
Similar to asset injection, head management follows the same idea: we can dynamically attach data to the render `context` in a component's lifecycle, and then interpolate those data in `template`.
44

5-
To do that we need to have access to the SSR context inside a nested component. We can simply pass the `context` to `createApp()` and expose it on the root instance's `$options`:
5+
> In version >=2.3.2, you can directly access the SSR context in a component as `this.$ssrContext`. In older versions you'd have to manually inject the SSR context by passing it to `createApp()` and expose it on the root instance's `$options` - child components can then access it via `this.$root.$options.ssrContext`.
66
7-
``` js
8-
// app.js
9-
10-
export function createApp (ssrContext) {
11-
// ...
12-
const app = new Vue({
13-
router,
14-
store,
15-
// all child components can access this as this.$root.$options.ssrContext
16-
ssrContext,
17-
render: h => h(App)
18-
})
19-
// ...
20-
}
21-
```
22-
23-
This can also be done via `provide/inject`, but since we know it's going to be on `$root`, we can avoid the injection resolution costs.
24-
25-
With the context injected, we can write a simple mixin to perform title management:
7+
We can write a simple mixin to perform title management:
268

279
``` js
2810
// title-mixin.js
@@ -42,7 +24,7 @@ const serverTitleMixin = {
4224
created () {
4325
const title = getTitle(this)
4426
if (title) {
45-
this.$root.$options.ssrContext.title = title
27+
this.$ssrContext.title = title
4628
}
4729
}
4830
}

0 commit comments

Comments
 (0)