index.js
1.63 KB
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
import { defineStore } from 'pinia';
// import { testStore } from './test'; // 另一个store
import _ from 'lodash';
import { useRouter } from 'vue-router'
export const mainStore = defineStore('main', {
state: () => {
return {
msg: 'Hello world',
count: 0,
auth: false,
comment_num: 0,
video_detail: {},
scrollTop: 0,
scrollTopCollection: 0,
scrollTopLike: 0,
scrollTopPerson: 0,
keepPages: ['default'], // 很坑爹,空值全部都缓存
};
},
getters: {
getKeepPages () {
return this.keepPages
},
// getTestStoreList () {
// return testStore().list // 返回另一个store的值
// }
},
actions: {
changeState (state) {
this.auth = state;
},
changeCommentNum (num) {
this.comment_num = num;
},
changeVideoDetail (v) {
this.video_detail = v;
},
changeScrollTop (v) {
this.scrollTop = v;
},
changeScrollTopCollection (v) {
this.scrollTopCollection = v;
},
changeScrollTopLike (v) {
this.scrollTopLike = v;
},
changeScrollTopPerson (v) {
this.scrollTopPerson = v;
},
changeKeepPages () { // 清空所有缓存,用一个不存在的值覆盖
this.keepPages = ['default'];
},
keepThisPage () { // 新增缓存页
const $router = useRouter();
const page = $router.currentRoute.value.meta.name;
this.keepPages.push(page);
},
removeThisPage () { // 删除缓存页
const $router = useRouter();
const page = $router.currentRoute.value.meta.name;
_.remove(this.keepPages, item => item === page)
}
},
});