new router

This commit is contained in:
Theophyl Hoguet committed 2023-03-15 21:51:33 +01:00
1 parent af1dfe275f
commit d701d59f17
4 files changed
+46 -39

No files matched your search

+15 -32
View File
@@ -8,11 +8,6 @@ import { api } from '@/http-api'
import { ImageType, ImageClass } from './image'; import { ImageType, ImageClass } from './image';
</script> </script>
<script lang="ts"> <script lang="ts">
const routes: { [key: string]: string } = {
'/': "Home",
'Gallery': "Gallery",
'Upload': "Upload"
}
export default defineComponent({ export default defineComponent({
components: { components: {
Home, Home,
@@ -24,15 +19,9 @@ export default defineComponent({
return { return {
images: new Map<Number, ImageType>(), images: new Map<Number, ImageType>(),
currentPath: window.location.hash, currentPath: window.location.hash,
sent: false,
file: null as FileList | null file: null as FileList | null
} }
}, },
computed: {
currentView(): string {
return routes[this.currentPath.slice(1) || '/'] || "notFound";
}
},
methods: { methods: {
async updateImageList(sleep: number) { async updateImageList(sleep: number) {
setTimeout(() => { setTimeout(() => {
@@ -48,21 +37,10 @@ export default defineComponent({
api.deleteImage(id).then(() => { api.deleteImage(id).then(() => {
this.updateImageList(100); this.updateImageList(100);
}) })
},
isActive(route: string) {
if (route === undefined) {
if (this.currentPath === "")
return 'router active';
route = "/";
}
return this.currentPath.endsWith(route) ? 'router active' : 'router';
} }
}, },
mounted() { created() {
this.updateImageList(0); this.updateImageList(0);
window.addEventListener('hashchange', () => {
this.currentPath = window.location.hash;
});
} }
}) })
</script> </script>
@@ -71,15 +49,16 @@ export default defineComponent({
<div class="navi"> <div class="navi">
<nav> <nav>
<ul> <ul>
<li v-for="route in routes" :class="isActive(routes[route])"> <li><router-link to="/">Home</router-link></li>
<a :href="'#' + (routes[route] || '/')"> <span>{{ route }}</span></a> <li><router-link to="/gallery">Gallery</router-link></li>
</li> <li><router-link to="/upload">Upload</router-link></li>
</ul> </ul>
</nav> </nav>
</div> </div>
</header> </header>
<component :is="currentView" :key="sent" :images="images" @delete="deleteFile" <div class="content">
@updateImageList="updateImageList(100)" /> <RouterView :images="images" @delete="deleteFile" @updateImageList="updateImageList(100)" />
</div>
</template> </template>
<style scoped> <style scoped>
.navi { .navi {
@@ -103,24 +82,28 @@ ul>li+li {
margin-left: 30px; margin-left: 30px;
} }
.content {
margin-top: 100px;
}
ul>li { ul>li {
position: relative; position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
padding: 5px 15px;
border-radius: 60px;
} }
.active { .router-link-active {
background-color: #646cff; background-color: #646cff;
} }
.active>a { .router-link-active>a {
color: rgb(205, 201, 194); color: rgb(205, 201, 194);
} }
a { a {
padding: 5px 15px;
border-radius: 60px;
color: rgb(172, 165, 154); color: rgb(172, 165, 154);
text-decoration: none; text-decoration: none;
font-family: "Aeonik", sans-serif; font-family: "Aeonik", sans-serif;
+6 -1
View File
@@ -1,5 +1,10 @@
import { createApp } from 'vue' import { createApp } from 'vue'
import './style.css' import './style.css'
import App from './App.vue' import App from './App.vue'
import router from './router'
createApp(App).mount('#app') const app = createApp(App)
app.use(router)
app.mount('#app')
+24
View File
@@ -0,0 +1,24 @@
import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'home',
component: () => import('../components/Home.vue')
},
{
path: '/gallery',
name: 'gallery',
component: () => import('../components/Gallery.vue')
},
{
path: '/upload',
name: "upload",
component: () => import('../components/Upload.vue')
}
]
})
export default router
+1 -6
View File
@@ -4,7 +4,7 @@
line-height: 24px; line-height: 24px;
font-weight: 400; font-weight: 400;
color-scheme: light dark; color-scheme: dark;
color: rgba(255, 255, 255, 0.87); color: rgba(255, 255, 255, 0.87);
background-color: #242424; background-color: #242424;
@@ -56,12 +56,7 @@ input:focus+label {
outline: 4px auto -webkit-focus-ring-color; outline: 4px auto -webkit-focus-ring-color;
} }
.card {
padding: 2em;
}
#app { #app {
max-width: 1280px;
margin: 0 auto; margin: 0 auto;
padding: 2rem; padding: 2rem;
text-align: center; text-align: center;