Add basic layouts

This commit is contained in:
Christian Cueni 2022-04-20 14:30:28 +02:00
parent 5be17d6c3e
commit 1ecd680d8e
9 changed files with 109 additions and 169 deletions

View File

@ -1,59 +1,14 @@
# client
# VBV Client
This template should help get you started developing with Vue 3 in Vite.
VBV Frontend
## Recommended IDE Setup
## Installation
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.vscode-typescript-vue-plugin).
`npm run install`
## Type Support for `.vue` Imports in TS
## Run
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.
`npm run dev`
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:
1. Disable the built-in TypeScript Extension
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.
## Customize configuration
See [Vite Configuration Reference](https://vitejs.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Type-Check, Compile and Minify for Production
```sh
npm run build
```
### Run Unit Tests with [Vitest](https://vitest.dev/)
```sh
npm run test:unit
```
### Run End-to-End Tests with [Cypress](https://www.cypress.io/)
```sh
npm run build
npm run test:e2e # or `npm run test:e2e:ci` for headless testing
```
### Lint with [ESLint](https://eslint.org/)
```sh
npm run lint
```
## Vue layouts
[How layouts are implemented](https://itnext.io/vue-tricks-smart-layouts-for-vuejs-5c61a472b69b)

View File

@ -1,118 +1,11 @@
<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from '@/components/HelloWorld.vue'
</script>
<template>
<header>
<img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />
<div class="wrapper">
<HelloWorld msg="You did it!" />
<nav>
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/about">About</RouterLink>
</nav>
<div id="app">
<AppLayout>
<router-view/>
</AppLayout>
</div>
</header>
<RouterView />
</template>
<style>
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
font-weight: normal;
}
header {
line-height: 1.5;
max-height: 100vh;
}
.logo {
display: block;
margin: 0 auto 2rem;
}
a,
.green {
text-decoration: none;
color: hsla(160, 100%, 37%, 1);
transition: 0.4s;
}
@media (hover: hover) {
a:hover {
background-color: hsla(160, 100%, 37%, 0.2);
}
}
nav {
width: 100%;
font-size: 12px;
text-align: center;
margin-top: 2rem;
}
nav a.router-link-exact-active {
color: var(--color-text);
}
nav a.router-link-exact-active:hover {
background-color: transparent;
}
nav a {
display: inline-block;
padding: 0 1rem;
border-left: 1px solid var(--color-border);
}
nav a:first-of-type {
border: 0;
}
@media (min-width: 1024px) {
body {
display: flex;
place-items: center;
}
#app {
display: grid;
grid-template-columns: 1fr 1fr;
padding: 0 2rem;
}
header {
display: flex;
place-items: center;
padding-right: calc(var(--section-gap) / 2);
}
header .wrapper {
display: flex;
place-items: flex-start;
flex-wrap: wrap;
}
.logo {
margin: 0 2rem 0 0;
}
nav {
text-align: left;
margin-left: -1rem;
font-size: 1rem;
padding: 1rem 0;
margin-top: 1rem;
}
}
</style>
<script setup lang="ts">
import AppLayout from "@/layouts/AppLayout.vue";
</script>

View File

@ -0,0 +1,18 @@
<template>
<nav class="bg-blue-dark flex flex-row text-white">
<p>Ich bin ein myVBV Header</p>
<ul>
<li>Ich bin ein myVBV link</li>
</ul>
</nav>
</template>
<script>
export default {
name: "MainNavigationBar"
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,18 @@
<template>
<nav class="bg-blue-dark flex flex-row text-white">
<p>Ich bin ein VBV Header</p>
<ul>
<li>Ich bin ein VBV link</li>
</ul>
</nav>
</template>
<script>
export default {
name: "VBVNavigationBar"
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,35 @@
<template>
<component :is="layout">
<slot />
</component>
</template>
<script>
import AppLayoutDefault from './AppLayoutDefault.vue'
import { markRaw, watch, shallowRef } from 'vue'
import { useRoute } from 'vue-router'
export default {
name: 'AppLayout',
setup() {
// https://stackoverflow.com/questions/69048657/dynamic-layout-in-vue-3-with-vite
const layout = shallowRef(AppLayoutDefault)
const route = useRoute()
watch(
() => route.meta?.layout,
async metaLayout => {
try {
if (metaLayout === undefined) {
return false
}
const component = await import(/* @vite-ignore */ `./${metaLayout}.vue`)
layout.value = markRaw(component?.default || AppLayoutDefault)
} catch (e) {
layout.value = markRaw(AppLayoutDefault)
}
},
{ immediate: true }
)
return { layout }
}
}
</script>

View File

@ -0,0 +1,12 @@
<template>
<VBVNavigationBar />
<MainNavigationBar />
<div>
<slot />
</div>
</template>
<script setup lang="ts">
import VBVNavigationBar from '@/components/VBVNavigationBar.vue'
import MainNavigationBar from '@/components/MainNavigationBar.vue'
</script>

View File

@ -0,0 +1,5 @@
<template>
<div>
<slot />
</div>
</template>

View File

@ -16,7 +16,10 @@ const router = createRouter({
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import('../views/AboutView.vue')
component: () => import('../views/AboutView.vue'),
meta: {
layout: 'NoNavbarDemoLayout'
}
},
{
path: "/login",

View File

@ -6,6 +6,7 @@ module.exports = {
],
theme: {
colors: {
'white': '#FFFFFF',
'blue-dark': '#00224D'
},
extend: {},