You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/head.md
+3-21Lines changed: 3 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -2,27 +2,9 @@
2
2
3
3
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`.
4
4
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`.
6
6
7
-
```js
8
-
// app.js
9
-
10
-
exportfunctioncreateApp (ssrContext) {
11
-
// ...
12
-
constapp=newVue({
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:
0 commit comments