13
13
</template >
14
14
15
15
<script >
16
- import { value , onCreated } from ' vue-function-api' ;
17
- import { useState , useActions } from ' @u3u/vue-hooks' ;
16
+ import { value , watch , onCreated } from ' vue-function-api' ;
17
+ import { useState , useActions , useRouter } from ' @u3u/vue-hooks' ;
18
18
19
19
import types from ' ../types' ;
20
20
import NewsItem from ' ../components/NewsItem.vue' ;
@@ -28,18 +28,28 @@ export default {
28
28
const { newsList , loading } = useState ([' newsList' , ' loading' ]);
29
29
const { GET_NEWS } = useActions ([types .GET_NEWS ]);
30
30
const currentPage = value (1 );
31
+ const { route } = useRouter ();
31
32
32
- onCreated (() => {
33
+ const setType = (type ) => {
34
+ currentPage .value = 1 ;
33
35
GET_NEWS ({
34
- type: ' news ' ,
36
+ type,
35
37
page: currentPage .value ,
36
38
});
39
+ };
40
+
41
+ watch (() => route .value .params .type , (type ) => {
42
+ setType (type);
43
+ });
44
+
45
+ onCreated (() => {
46
+ setType (route .value .params .type );
37
47
});
38
48
39
49
const loadMore = () => {
40
50
currentPage .value += 1 ;
41
51
GET_NEWS ({
42
- type: ' news ' ,
52
+ type: route . value . params . type ,
43
53
page: currentPage .value ,
44
54
});
45
55
};
0 commit comments