File tree Expand file tree Collapse file tree 12 files changed +168
-84
lines changed Expand file tree Collapse file tree 12 files changed +168
-84
lines changed Original file line number Diff line number Diff line change 26
26
"js-cookie" : " ^2.2.1" ,
27
27
"markdown-it" : " ^12.0.4" ,
28
28
"nprogress" : " ^0.2.0" ,
29
- "vue" : " ^3.1.4" ,
29
+ "pinia" : " ^2.0.0-rc.9" ,
30
+ "vue" : " ^3.2.0" ,
30
31
"vue-global-api" : " ^0.2.1" ,
31
32
"vue-router" : " ^4.0.3" ,
32
33
"vue-toastification" : " ^2.0.0-rc.1" ,
Original file line number Diff line number Diff line change 5
5
<script lang="ts" setup>
6
6
import { useHead } from " @vueuse/head" ;
7
7
import { POSITION , useToast } from " vue-toastification" ;
8
- import { useStore } from " vuex " ;
8
+ import { useStore } from " ~/store/pinia " ;
9
9
import { useRoute } from " vue-router" ;
10
10
11
11
import GithubStar from " ~/components/common/GithubStar.vue" ;
12
- import { ACTIONS } from " ~/store/type" ;
13
12
import { useBaiduInit } from " ./utils/pageView" ;
14
13
const store = useStore ();
15
14
const toast = useToast ();
@@ -36,9 +35,10 @@ onMounted(async () => {
36
35
37
36
// 应用初始化 Store 数据
38
37
// 用户登录信息
39
- store .dispatch (ACTIONS .GET_AUTHED_USER_INFO );
38
+ store .GetAuthedUserInfo ();
39
+
40
40
// 用户主题信息
41
- store .dispatch ( ACTIONS . GET_CATEGORY_LIST );
41
+ store .GetCategoryList ( );
42
42
// 高亮初始化
43
43
(window as any )?.hljs ?.initHighlightingOnLoad ?.();
44
44
});
Original file line number Diff line number Diff line change 1
1
<script lang="ts" setup>
2
2
import { useRouter } from " vue-router" ;
3
3
import { useToast } from " vue-toastification" ;
4
- import { useStore } from " vuex " ;
5
- import type { StoreType } from " ~/store/index " ;
4
+ import { useStore } from " ~/store/pinia " ;
5
+
6
6
import { GetCommentList , PostComment } from " ~/api/article" ;
7
7
import { DefaultFormat } from " ~/utils/time" ;
8
8
@@ -13,9 +13,9 @@ const props = defineProps({
13
13
14
14
const toast = useToast ();
15
15
const router = useRouter ();
16
- const store = useStore < StoreType > ();
16
+ const store = useStore ();
17
17
18
- const isAuthed = computed (() => store ?.state ?. User ?.Id ?? 0 > 0 );
18
+ const isAuthed = computed (() => store ?.User ?.Id ?? 0 > 0 );
19
19
20
20
// 评论值
21
21
// ref: Comment = ""
Original file line number Diff line number Diff line change 21
21
</template >
22
22
<script lang="ts" setup>
23
23
import { useRouter } from " vue-router" ;
24
- import { useStore } from " vuex" ;
25
- import type { StoreType } from " ~/store" ;
24
+ import { useStore } from " ~/store/pinia" ;
26
25
27
26
const router = useRouter ();
28
27
@@ -40,15 +39,15 @@ const ToIndex = () => {
40
39
router .push (" /" );
41
40
// window.location.href = "/"
42
41
};
43
- const store = useStore < StoreType > ();
42
+ const store = useStore ();
44
43
// 判断用户是否作者
45
44
const isAuthor = computed (
46
- () => !! store .state . User ?.Roles ?.find (i => i .Title == " Author" )
45
+ () => !! store .User ?.Roles ?.find (i => i .Title == " Author" )
47
46
);
48
47
// 获取用户ID
49
- const userId = computed (() => store .state . User .Id ?? 0 );
48
+ const userId = computed (() => store .User .Id ?? 0 );
50
49
// 获取用户头像
51
- const avatar = computed (() => store .state . User .Avatar ?? " " );
50
+ const avatar = computed (() => store .User .Avatar ?? " " );
52
51
// props
53
52
const title = props .title ;
54
53
const brief = props .brief ;
Original file line number Diff line number Diff line change 1
- import { useStore } from "vuex" ;
2
-
3
- import { StoreType } from "~/store" ;
1
+ import { useStore } from "~/store/pinia" ;
4
2
5
3
import "./index.css" ;
6
4
const DefaultLayout = defineComponent ( {
7
5
name : "content-layout" ,
8
6
setup ( ) {
9
- const store = useStore < StoreType > ( ) ;
7
+ const store = useStore ( ) ;
10
8
return {
11
- CategoryList : computed ( ( ) => store . state . Article . CategoryList ) ,
9
+ CategoryList : computed ( ( ) => store . Article . CategoryList ) ,
12
10
} ;
13
11
} ,
14
12
render ( ) {
Original file line number Diff line number Diff line change 23
23
</template >
24
24
25
25
<script lang="ts" setup>
26
- import { useStore } from " vuex " ;
26
+ import { useStore } from " ~/store/pinia " ;
27
27
28
- import type { StoreType } from " ~/store " ;
28
+ const store = useStore () ;
29
29
30
- const store = useStore <StoreType >();
31
-
32
- const CategoryList = computed (() => store .state .Article .CategoryList );
30
+ const CategoryList = computed (() => store .Article .CategoryList );
33
31
</script >
34
32
35
33
<style scoped>
Original file line number Diff line number Diff line change 1
1
import { createApp } from "vue" ;
2
2
import { createHead } from "@vueuse/head" ;
3
+ import { createPinia } from "pinia" ;
3
4
import "vue-global-api" ;
4
5
import Toast , { PluginOptions , POSITION } from "vue-toastification" ;
5
6
import "vue-toastification/dist/index.css" ;
@@ -22,7 +23,17 @@ const options: PluginOptions = {
22
23
transition : "Vue-Toastification__fade" ,
23
24
} ;
24
25
const head = createHead ( ) ;
26
+ const pinia = createPinia ( ) ;
27
+ pinia . use ( ( { store } ) => {
28
+ store . $subscribe ( t => {
29
+ console . log ( "store state changed" , t ) ;
30
+ } ) ;
31
+ store . $onAction ( a => {
32
+ console . log ( "store action fired" , a ) ;
33
+ } ) ;
34
+ } ) ;
25
35
createApp ( App )
36
+ . use ( pinia )
26
37
. use ( Toast , options )
27
38
. use ( head )
28
39
. use ( RouterInstance )
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ export type StoreType = {
11
11
} ;
12
12
} ;
13
13
14
+ /**
15
+ * @deprecated 废弃
16
+ */
14
17
const Store = createStore < StoreType > ( {
15
18
state ( ) {
16
19
return {
You can’t perform that action at this time.
0 commit comments