/
vue.ts
112 lines (78 loc) · 1.86 KB
/
vue.ts
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
/**
* Test extended type definitions of Vue interfaces
* @nuxt/types/app/vue.d.ts
*/
import Vue from 'vue'
import type { Middleware } from '..'
const options: Vue.ComponentOptions<Vue> = {}
// asyncData
options.asyncData = () => {
return {
foo: 'bar'
}
}
options.asyncData = () => undefined
// fetch
options.fetch = ({ store }) => {
return Promise.resolve('bar').then((res) => {
store.commit('setFoo', res)
})
}
options.fetch = async ({ store }) => {
const res = await Promise.resolve('bar')
store.commit('setFoo', res)
}
// key
options.key = 'foo'
options.key = to => to.fullPath
// head
const metaInfo = {
title: 'Home',
meta: [
{ hid: 'description', name: 'description', content: 'My custom description' }
]
}
options.head = metaInfo
options.head = () => metaInfo
// layout
options.layout = 'foo'
options.layout = () => 'foo'
// loading
options.loading = true
// middleware
const middlewares: Middleware[] = [
'foo',
() => {},
async () => {}
]
options.middleware = middlewares
options.middleware = middlewares[0]
options.middleware = middlewares[1]
options.middleware = middlewares[2]
// scrollToTop
options.scrollToTop = true
// transition
options.transition = 'foo'
options.transition = { name: 'foo' }
options.transition = () => 'foo'
options.transition = () => {
return { name: 'foo' }
}
// validate
options.validate = () => true
options.validate = async () => {
const valid = await Promise.resolve(true)
return valid
}
// watchQuery
options.watchQuery = true
options.watchQuery = ['foo', 'bar']
// $nuxt
const vm = new Vue(options)
if (vm.$nuxt.$loading.fail) { vm.$nuxt.$loading.fail() }
vm.$nuxt.$loading.finish()
if (vm.$nuxt.$loading.increase) { vm.$nuxt.$loading.increase(1) }
if (vm.$nuxt.$loading.pause) { vm.$nuxt.$loading.pause() }
vm.$nuxt.$loading.start()
vm.$nuxt.isOffline = true
vm.$nuxt.isOnline = true