diff --git a/src/App.vue b/src/App.vue index 0b7875d..0ffdfc2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -18,6 +18,12 @@
Loading...
+ + @@ -25,9 +31,11 @@ import PostForm from '@/components/PostForm.vue'; import PostList from '@/components/PostList.vue'; import axios from 'axios'; +import MyPagination from '@/components/ui/Pagination.vue'; export default { components: { + MyPagination, PostForm, PostList }, @@ -41,7 +49,10 @@ export default { {value: 'title', name: 'По названию'}, {value: 'body', name: 'По описанию'} ], - searchQuery: '' + searchQuery: '', + page: 1, + limit: 10, + totalPages: 0 } }, methods: { @@ -57,11 +68,20 @@ export default { }, async fetchPosts() { try { - const {data} = await axios.get('https://jsonplaceholder.typicode.com/posts?_limit=10'); - this.posts = data + const { data, headers } = await axios.get(`https://jsonplaceholder.typicode.com/posts`, { + params: { + _limit: this.limit, + _page: this.page + } + }); + this.posts = data; + this.totalPages = Math.ceil(headers['x-total-count'] / this.limit); } catch (e) { alert(e.message); } + }, + changePage(newPage) { + this.page = newPage; } }, async mounted() { @@ -91,6 +111,9 @@ export default { } else { document.body.style.overflow = 'auto'; } + }, + page() { + this.fetchPosts() } } } diff --git a/src/components/Post.vue b/src/components/Post.vue index 7a33586..50bf12d 100644 --- a/src/components/Post.vue +++ b/src/components/Post.vue @@ -1,6 +1,7 @@