news-list.js
1.41 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
66
67
68
69
70
71
72
73
74
75
76
import api from '@/api/api'
import {
httpGet,
httpPost
} from '@/api/fetch-api.js'
import Pagination from '@/components/pagination/pagination.vue'
import { getDateYMD } from "@/utils/biz.js";
export default {
name: "newsList",
components: {
Pagination
},
data() {
return {
key: 'value',
queryForm: {
l: "tc",
page: 1,
size: 10
},
totalPage: 0,
totalItem : 0,
news: []
}
},
methods: {
toNewsDetail(newsCode) {
this.$router.push({
path: "/news/detail",
query: {
c: newsCode
}
});
},
selPage(val) {
let {
page
} = val;
// this.queryForm.page = page;
this.$router.push({
path: "/news/list",
query: {
page: page
}
});
this.initData();
},
initData() {
let l = this.$i18n.locale;
this.queryForm.l = l;
let page = this.$route.query.page || 1;
this.queryForm.page = page;
this.$nextTick(()=>{
this.$refs.pagination.selPage(page);
});
httpGet({ url: api.newsList, data: this.queryForm }).then(res => {
let newsList = res.list;
newsList.forEach(element => {
element.dateFormat = getDateYMD(element.createAt);
});
this.$set(this, 'news', newsList);
this.totalPage = Math.ceil(res.total / this.queryForm.size);
this.totalItem = res.total;
});
}
},
mounted() { },
created() {
document.documentElement.scrollTop = 0;
document.body.scrollTop = 0;
this.initData();
}
}