forked from nuxt/vue-meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
138 lines (123 loc) · 2.71 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import Vue from 'vue'
import VueMeta from 'vue-meta'
import Router from 'vue-router'
Vue.use(Router)
Vue.use(VueMeta, {
refreshOnceOnNavigation: true
})
let metaUpdated = 'no'
const ChildComponent = {
name: 'child-component',
props: ['page'],
template: `<div>
<h3>You're looking at the <strong>{{ page }}</strong> page</h3>
<p>Has metaInfo been updated due to navigation? {{ metaUpdated }}</p>
</div>`,
metaInfo () {
return {
title: `${this.page} - ${this.date && this.date.toTimeString()}`,
bodyAttrs: {
class: 'child-component'
},
afterNavigation () {
metaUpdated = 'yes'
}
}
},
data () {
return {
date: null,
metaUpdated
}
},
mounted () {
this.interval = setInterval(() => {
this.date = new Date()
}, 1000)
},
destroyed () {
clearInterval(this.interval)
}
}
// this wrapper function is not a requirement for vue-router,
// just a demonstration that render-function style components also work.
// See https://github.com/nuxt/vue-meta/issues/9 for more info.
function view (page) {
return {
name: `section-${page}`,
render (h) {
return h(ChildComponent, {
props: { page }
})
}
}
}
const router = new Router({
mode: 'history',
base: '/vue-router',
routes: [
{ path: '/', component: view('home') },
{ path: '/about', component: view('about') }
]
})
const App = {
router,
template: `
<div id="app">
<h1>vue-router</h1>
<router-link to="/">Home</router-link>
<router-link to="/about">About</router-link>
<transition name="page" mode="out-in">
<router-view></router-view>
</transition>
<p>Inspect Element to see the meta info</p>
</div>
`
}
const app = new Vue(App)
const { set, remove } = app.$meta().addApp('custom')
set({
bodyAttrs: {
class: 'custom-app'
},
meta: [
{ charset: 'utf=8' }
]
})
setTimeout(() => remove(), 3000)
app.$mount('#app')
/*
const waitFor = time => new Promise(r => setTimeout(r, time || 1000))
const o = {
meta: [{ a: 1 }]
}
const ob = Vue.observable(o)
const root = new Vue({
beforeCreate() {
this.meta = ob.meta
this.$options.computed = this.$options.computed || {}
this.$options.computed['$ob'] = () => {
return { meta: this.meta }
}
},
created() {
console.log('HERE')
this.$watch('$ob', (a, b) => {
console.log('WATCHER', this.$ob.meta[0].a, a.meta[0].a, b.meta[0].a, diff(a, b))
}, { deep: true })
},
render(h) {
return h('div', null, 'test')
}
})
async function main () {
root.$mount('#app')
console.log(root)
await waitFor(500)
root.meta[0].a = 2
await waitFor(100)
ob.meta[0].a = 3
await waitFor(100)
}
main()
/**/