forked from nuxt/vue-meta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
88 lines (84 loc) · 1.63 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
import Vue from 'vue'
import VueMeta from 'vue-meta'
Vue.use(VueMeta)
window.users = []
new Vue({
metaInfo () {
return {
title: 'Async Callback',
titleTemplate: '%s | Vue Meta Examples',
script: [
{
skip: this.count < 2,
vmid: 'potatoes',
src: '/user-3.js',
async: true,
callback: this.updateCounter
},
{
skip: this.count < 1,
vmid: 'vegetables',
src: '/user-2.js',
async: true,
callback: this.updateCounter
},
{
vmid: 'meat',
src: '/user-1.js',
async: true,
callback: el => this.loadCallback(el.getAttribute('data-vmid'))
},
...this.scripts
]
}
},
data () {
return {
count: 0,
scripts: [],
users: window.users
}
},
watch: {
count (val) {
if (val === 3) {
this.addScript()
}
}
},
methods: {
updateCounter () {
this.count++
},
addScript () {
this.scripts.push({
src: '/user-4.js',
callback: () => {
this.updateCounter()
}
})
},
loadCallback (vmid) {
if (vmid === 'meat') {
this.updateCounter()
}
}
},
template: `
<div id="app">
<h1>Async Callback</h1>
<p>{{ count }} scripts loaded</p>
<div>
<h2>Users</h2>
<ul>
<li
v-for="user in users"
:key="user.id"
>
<strong>{{ user.id }}</strong>: {{ user.name }}
</li>
</ul>
</div>
</div>
`
}).$mount('#app')