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