modified: serv_nginx/bbvue/src/views/News.vue

to apiClient form http
This commit is contained in:
2025-10-16 07:01:19 +05:00
parent f527e85e4c
commit 8628b5d238
+9 -8
View File
@@ -274,6 +274,7 @@
<script> <script>
import { mapState, mapActions } from 'pinia' import { mapState, mapActions } from 'pinia'
import { useAuthStore } from '../stores/auth' import { useAuthStore } from '../stores/auth'
import { apiClient } from '../stores/helpers/api';
export default { export default {
// eslint-disable-next-line vue/multi-word-component-names // eslint-disable-next-line vue/multi-word-component-names
@@ -335,7 +336,7 @@ export default {
this.loading = true this.loading = true
this.error = '' this.error = ''
try { try {
const response = await this.$http.get('/news') const response = await apiClient.get('/news')
this.news = response.data.news || response.data this.news = response.data.news || response.data
} catch (error) { } catch (error) {
console.error('Failed to fetch news:', error) console.error('Failed to fetch news:', error)
@@ -347,7 +348,7 @@ export default {
async fetchComments(newsId) { async fetchComments(newsId) {
try { try {
const response = await this.$http.get(`/news/${newsId}/comments`) const response = await apiClient.get(`/news/${newsId}/comments`)
this.comments = response.data.comments || response.data this.comments = response.data.comments || response.data
} catch (error) { } catch (error) {
console.error('Failed to fetch comments:', error) console.error('Failed to fetch comments:', error)
@@ -357,7 +358,7 @@ export default {
async openNewsModal(newsItem) { async openNewsModal(newsItem) {
try { try {
const response = await this.$http.get(`/news/${newsItem.id}`) const response = await apiClient.get(`/news/${newsItem.id}`)
this.selectedNews = response.data this.selectedNews = response.data
await this.fetchComments(newsItem.id) await this.fetchComments(newsItem.id)
} catch (error) { } catch (error) {
@@ -374,7 +375,7 @@ export default {
this.commentLoading = true this.commentLoading = true
try { try {
await this.$http.post(`/news/${this.selectedNews.id}/comments`, { await apiClient.post(`/news/${this.selectedNews.id}/comments`, {
content: this.newComment content: this.newComment
}) })
@@ -393,7 +394,7 @@ export default {
if (!confirm('Удалить этот комментарий?')) return if (!confirm('Удалить этот комментарий?')) return
try { try {
await this.$http.delete(`/news/comments/${commentId}`) await apiClient.$.delete(`/news/comments/${commentId}`)
await this.fetchComments(this.selectedNews.id) await this.fetchComments(this.selectedNews.id)
await this.fetchNews() await this.fetchNews()
} catch (error) { } catch (error) {
@@ -433,9 +434,9 @@ export default {
this.newsLoading = true this.newsLoading = true
try { try {
if (this.editingNews) { if (this.editingNews) {
await this.$http.put(`/news/${this.editingNews.id}`, this.newsForm) await apiClient.put(`/news/${this.editingNews.id}`, this.newsForm)
} else { } else {
await this.$http.post('/news', this.newsForm) await apiClient.post('/news', this.newsForm)
} }
this.closeNewsFormModal() this.closeNewsFormModal()
@@ -452,7 +453,7 @@ export default {
if (!confirm('Удалить эту новость? Это действие нельзя отменить.')) return if (!confirm('Удалить эту новость? Это действие нельзя отменить.')) return
try { try {
await this.$http.delete(`/news/${newsId}`) await apiClient.delete(`/news/${newsId}`)
await this.fetchNews() await this.fetchNews()
if (this.showNewsModal) { if (this.showNewsModal) {
this.closeNewsModal() this.closeNewsModal()