Ж
Size: a a a
Ж
Ж
asyncData(context) {
let { $axios, route } = context;
let {
props: {
default: { loadUrl },
},
} = route.matched.find(r => r.path.endsWith('categories'));
console.log(route.matched.find(r => r.path.endsWith('categories')));
return $axios
.get(`/api/media/${loadUrl}`)
.then(({ data }) => ({ categories: data.items || [] }))
.catch(e => {
console.error(`ОШИБКА В ПУТИ - /api/media/${loadUrl}`);
return {
categories: [],
};
});
},
watch: {
loadUrl: {
immediate: true,
handler: 'loadCategories',
},
},
loadCategories() {
return this.$axios
.get(`/api/media/${this.loadUrl}`)
.then(({ data }) => (this.categories = data.items || []))
.catch(e => {
console.error(`ОШИБКА В ПУТИ - /api/media/${this.loadUrl}`);
this.categories = [];
});
},
Ж
Ж
<template>
<div
v-if="loading"
class="loading-page"
>
<p>
Loading...
frefreferf
frefre
</p>
</div>
</template>
<script>
export default {
data: () => ({
loading: false,
}),
methods: {
start () {
console.log('1223')
this.loading = true
},
finish () {
this.loading = false
},
},
}
</script>
<style scoped>
.loading-page {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(255, 255, 255, 0.8);
text-align: center;
padding-top: 200px;
font-size: 30px;
font-family: sans-serif;
}
</style>
asyncData() {
return new Promise(res => setTimeout(() => res({ qwe: 'test' }), 2000));
},
Ж
Ж
Ж
nG
export const getters = {
ALL_CATS(state){
return state.categories;
},
MAIN_CATS(state){
return state.categories.filter(c => c.parent_id === 0);
},
SUB_CATS: state => id => {
return state.categories.filter(c => c.parent_id === id);
},
};<script>
import {mapActions, mapGetters} from 'vuex'
export default {
computed: {
...mapGetters([
'ALL_CATS',
'MAIN_CATS',
'SUB_CATS',
]),
},
methods: {
...mapActions([
'GET_CATEGORIES'
]),
},
mounted() {
this.GET_CATEGORIES()
},
}
</script>
V💊
export const getters = {
ALL_CATS(state){
return state.categories;
},
MAIN_CATS(state){
return state.categories.filter(c => c.parent_id === 0);
},
SUB_CATS: state => id => {
return state.categories.filter(c => c.parent_id === id);
},
};<script>
import {mapActions, mapGetters} from 'vuex'
export default {
computed: {
...mapGetters([
'ALL_CATS',
'MAIN_CATS',
'SUB_CATS',
]),
},
methods: {
...mapActions([
'GET_CATEGORIES'
]),
},
mounted() {
this.GET_CATEGORIES()
},
}
</script>
R
DP
Ж
loading: { color: '#900000', height: '20px' },
Ж
Ж
DP
Ж
Ж
Ж
Ж