Перенес запросы на бэк из basya в стор pinia
Some checks failed
Gitea Actions / Build and deploy (push) Has been cancelled

This commit is contained in:
Dhaverd 2024-04-20 16:12:45 +08:00
parent e04bc5ba98
commit 35a93c343e
4 changed files with 34 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import './js/bootstrap'; import './js/bootstrap';
import {createApp} from 'vue' import {createApp} from 'vue'
import { createPinia } from 'pinia'
import App from './views/basya/Basya.vue' import App from './views/basya/Basya.vue'
import { createVuetify } from 'vuetify' import { createVuetify } from 'vuetify'
import { mdi } from "vuetify/iconsets/mdi"; import { mdi } from "vuetify/iconsets/mdi";
@ -8,9 +9,11 @@ import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives' import * as directives from 'vuetify/directives'
import '@mdi/font/css/materialdesignicons.css' import '@mdi/font/css/materialdesignicons.css'
const pinia = createPinia();
const vuetify = createVuetify({ const vuetify = createVuetify({
components, components,
directives directives
}) })
createApp(App).use(vuetify).mount("#app") createApp(App).use(vuetify).use(pinia).mount("#app")

20
resources/stores/basya.js Normal file
View File

@ -0,0 +1,20 @@
import {defineStore} from "pinia";
import axios from "axios";
export const useBasyaStore = defineStore('basya', {
state: () => ({
phrases: Object
}),
getters: {
},
actions: {
async getPhrases(){
await axios
.get('/api/v1/phrases')
.then((response) => {
this.phrases = response.data;
});
}
},
})

View File

@ -1,7 +1,7 @@
import {defineStore} from "pinia"; import {defineStore} from "pinia";
import axios from "axios"; import axios from "axios";
export const useScheduleStore = defineStore('Schedule', { export const useScheduleStore = defineStore('schedule', {
state: () => ({ state: () => ({
dates: Object, dates: Object,
links: Object, links: Object,

View File

@ -34,7 +34,8 @@
<script> <script>
import {ref} from 'vue'; import {ref} from 'vue';
import axios from "axios"; import {useBasyaStore} from "../../stores/basya.js";
export default { export default {
name: "Basya", name: "Basya",
data: () => ({ data: () => ({
@ -44,7 +45,8 @@ export default {
currentPhrase: ref(), currentPhrase: ref(),
winWidth: ref(document.documentElement.clientWidth), winWidth: ref(document.documentElement.clientWidth),
// size: ref(), // size: ref(),
isLess: false isLess: false,
basyaStore: useBasyaStore()
}), }),
methods: { methods: {
reloadPhrase(){ reloadPhrase(){
@ -61,13 +63,11 @@ export default {
} }
}, },
mounted() { mounted() {
axios this.basyaStore.getPhrases().then(()=>{
.get('/api/v1/phrases') this.phrases = this.basyaStore.phrases;
.then(response => { this.reloadPhrase();
this.phrases = response.data; this.fetching = false;
this.reloadPhrase(); })
this.fetching = false;
});
this.isLess = ref(this.winWidth.value <= 600 ? 'flex-column' : ''); this.isLess = ref(this.winWidth.value <= 600 ? 'flex-column' : '');
/* /*
this.size = this.winWidth <= 600 ? 'x-small' : this.size = this.winWidth <= 600 ? 'x-small' :