-
Notifications
You must be signed in to change notification settings - Fork 74
/
vuet.js
93 lines (90 loc) · 1.84 KB
/
vuet.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
import Vue from 'vue'
import Vuet from 'vuet'
Vue.use(Vuet)
const listData = () => ([
{
id: 1,
title: '1 title',
content: '1x1 content',
type: 'good'
},
{
id: 2,
title: '2 title',
content: '2x1 content',
type: 'share'
},
{
id: 3,
title: '3 title',
content: '3x1 content',
type: 'share'
},
{
id: 4,
title: '4 title',
content: '4x1 content',
type: 'good'
}
])
export default new Vuet({
data () {
return {}
},
modules: {
topic: {
list: {
data () {
return {
list: [],
fetchCount: 0
}
},
routeWatch: 'query',
async fetch ({ state }) {
const { type = 'all' } = this.app.$route.query
let list = listData()
if (type !== 'all') {
list = listData().filter((item) => item.type === type)
}
await new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, 1000)
})
return {
list,
fetchCount: ++state.fetchCount
}
}
},
detail: {
data () {
return {
id: null,
title: null,
content: null,
type: null,
fetchCount: 0
}
},
routeWatch: 'params.id',
async fetch ({ state }) {
const { id } = this.app.$route.params
await new Promise((resolve, reject) => {
setTimeout(() => {
resolve()
}, 1000)
})
const arr = listData()
for (let i = 0; i < arr.length; i++) {
if (arr[i].id === Number(id)) {
return { ...arr[i], fetchCount: ++state.fetchCount }
}
}
return {}
}
}
}
}
})