1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import language from "./common/language.js";
- import Service from "./common/service.js";
- new Vue({
- el: "#app",
- data: {
- list: [],
- total: 0,
- params: {
- page: 1,
- page_num: 6,
- },
- pagination_list: [],
- },
- mounted() {
- this.getList();
- },
- methods: {
- text(val) {
- return language[val][localStorage.getItem("language")];
- },
- lan_key(val) {
- return `${val}${localStorage.getItem("language") == "en" ? "_en" : ""}`;
- },
- changeCurrent(val) {
- if (val == this.params.page || val == "...") return;
- if (val < 1 || val > Math.ceil(this.total / this.params.page_num)) return;
- this.params.page = val;
- this.getList();
- },
- setPaginationList() {
- const allNum = Math.ceil(this.total / this.params.page_num);
- this.pagination_list = new Array(allNum)
- .fill(null)
- .map((_, index) => {
- if (index == 0 || index == allNum - 1) return index + 1;
- return Math.abs(index + 1 - this.params.page) >= 2
- ? Math.abs(index + 1 - this.params.page) == 2
- ? "..."
- : ""
- : index + 1;
- })
- .filter((i) => i);
- },
- getList() {
- Service.get_news(this.params)
- .then((res) => {
- this.list = res.data;
- this.total = res.total;
- this.setPaginationList();
- })
- .catch((err) => {
- console.log(err);
- });
- },
- },
- });
|