@@ -2,18 +2,35 @@ import triggerUpdate from '../client/triggerUpdate'
2
2
import { isUndefined , isFunction } from './typeof'
3
3
import { ensuredPush } from './ensure'
4
4
5
- export default function createMixin ( options ) {
5
+ export default function createMixin ( Vue , options ) {
6
6
// for which Vue lifecycle hooks should the metaInfo be refreshed
7
7
const updateOnLifecycleHook = [ 'activated' , 'deactivated' , 'beforeMount' ]
8
8
9
9
// watch for client side component updates
10
10
return {
11
11
beforeCreate ( ) {
12
+ Object . defineProperty ( this , '_hasMetaInfo' , {
13
+ get ( ) {
14
+ // Show deprecation warning once when devtools enabled
15
+ if ( Vue . config . devtools && ! this . $root . _vueMeta . hasMetaInfoDeprecationWarningShown ) {
16
+ console . warn ( 'VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please import hasMetaInfo and use hasMetaInfo(vm) instead' ) // eslint-disable-line no-console
17
+ this . $root . _vueMeta . hasMetaInfoDeprecationWarningShown = true
18
+ }
19
+ return ! ! this . _vueMeta
20
+ }
21
+ } )
22
+
12
23
// Add a marker to know if it uses metaInfo
13
24
// _vnode is used to know that it's attached to a real component
14
25
// useful if we use some mixin to add some meta tags (like nuxt-i18n)
15
26
if ( ! isUndefined ( this . $options [ options . keyName ] ) && this . $options [ options . keyName ] !== null ) {
16
- this . _hasMetaInfo = true
27
+ if ( ! this . $root . _vueMeta ) {
28
+ this . $root . _vueMeta = { }
29
+ }
30
+
31
+ if ( ! this . _vueMeta ) {
32
+ this . _vueMeta = true
33
+ }
17
34
18
35
// coerce function-style metaInfo to a computed prop so we can observe
19
36
// it on creation
@@ -39,18 +56,18 @@ export default function createMixin(options) {
39
56
// to triggerUpdate until this initial refresh is finished
40
57
// this is to make sure that when a page is opened in an inactive tab which
41
58
// has throttled rAF/timers we still immeditately set the page title
42
- if ( isUndefined ( this . $root . _vueMetaInitialized ) ) {
43
- this . $root . _vueMetaInitialized = this . $isServer
59
+ if ( isUndefined ( this . $root . _vueMeta . initialized ) ) {
60
+ this . $root . _vueMeta . initialized = this . $isServer
44
61
45
- if ( ! this . $root . _vueMetaInitialized ) {
62
+ if ( ! this . $root . _vueMeta . initialized ) {
46
63
const $rootMeta = this . $root . $meta ( )
47
64
48
65
ensuredPush ( this . $options , 'mounted' , ( ) => {
49
- if ( ! this . $root . _vueMetaInitialized ) {
66
+ if ( ! this . $root . _vueMeta . initialized ) {
50
67
// refresh meta in nextTick so all child components have loaded
51
68
this . $nextTick ( function ( ) {
52
69
$rootMeta . refresh ( )
53
- this . $root . _vueMetaInitialized = true
70
+ this . $root . _vueMeta . initialized = true
54
71
} )
55
72
}
56
73
} )
0 commit comments