add an example for reusing code

This commit is contained in:
Andreas Zweili 2021-09-06 20:07:22 +02:00
parent b7cb5d789d
commit 4605f7bd57
17 changed files with 12474 additions and 1 deletions

View File

@ -0,0 +1,3 @@
> 1%
last 2 versions
not dead

View File

@ -0,0 +1,17 @@
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended'
],
parserOptions: {
parser: 'babel-eslint'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
}

View File

@ -0,0 +1,22 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@ -0,0 +1,3 @@
{
"singleQuote": true
}

Binary file not shown.

View File

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
{
"name": "vue-first-app",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^3.0.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "^3.0.0-0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^7.0.0-0"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

View File

@ -0,0 +1,60 @@
<template>
<main>
<add-user></add-user>
<delete-user></delete-user>
</main>
</template>
<script>
import AddUser from './components/AddUser.vue';
import DeleteUser from './components/DeleteUser.vue';
export default {
components: {
AddUser,
DeleteUser,
},
};
</script>
<style>
* {
box-sizing: border-box;
}
html {
font-family: sans-serif;
}
body {
margin: 0;
}
main {
width: 40rem;
margin: 3rem auto;
}
section {
margin: 2rem auto;
border: 1px solid #ccc;
border-radius: 12px;
padding: 1rem;
}
button {
font: inherit;
background-color: #310131;
border: 1px solid #310131;
border-radius: 8px;
color: white;
padding: 0.5rem 1.5rem;
cursor: pointer;
}
button:hover,
button:active {
background-color: #770e77;
border-color: #770e77;
}
</style>

View File

@ -0,0 +1,21 @@
<template>
<user-alert v-if="alertIsVisible" title="Add a User?" @close="hideAlert">
<p>Do you want to continue with adding a user?</p>
</user-alert>
<section>
<h2>Add a User</h2>
<button @click="showAlert">Add User</button>
</section>
</template>
<script>
import UserAlert from '../components/UserAlert';
import alertMixin from '../mixins/alert';
export default {
components: {
UserAlert
},
mixins: [alertMixin]
};
</script>

View File

@ -0,0 +1,21 @@
<template>
<user-alert v-if="alertIsVisible" title="Delete the User?" @close="hideAlert">
<p>Do you want to continue with deleting a user?</p>
</user-alert>
<section>
<h2>Delete a User</h2>
<button @click="showAlert">Delete User</button>
</section>
</template>
<script>
import UserAlert from '../components/UserAlert';
import alertMixin from '../mixins/alert';
export default {
components: {
UserAlert
},
mixins: [alertMixin]
};
</script>

View File

@ -0,0 +1,71 @@
<template>
<div class="backdrop" @click="closeDialog"></div>
<dialog open>
<header>
<h2>{{ title }}</h2>
</header>
<div>
<slot></slot>
</div>
<menu>
<button @click="closeDialog">Close</button>
</menu>
</dialog>
</template>
<script>
export default {
props: ['title'],
emits: ['close'],
methods: {
closeDialog() {
this.$emit('close');
},
},
};
</script>
<style scoped>
.backdrop {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background-color: rgba(0, 0, 0, 0.75);
z-index: 10;
}
dialog {
margin: 0;
padding: 0;
border: none;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
position: fixed;
top: 30vh;
left: calc(50% - 15rem);
width: 30rem;
background-color: white;
z-index: 100;
overflow: hidden;
}
header {
width: 100%;
padding: 1rem;
background-color: #310131;
color: white;
}
dialog div {
padding: 1rem;
}
menu {
padding: 1rem;
display: flex;
justify-content: flex-end;
align-items: center;
}
</style>

View File

@ -0,0 +1,7 @@
import { createApp } from 'vue';
import App from './App.vue';
const app = createApp(App)
app.mount('#app');

View File

@ -0,0 +1,15 @@
export default {
data() {
return {
alertIsVisible: false
};
},
methods: {
showAlert() {
this.alertIsVisible = true;
},
hideAlert() {
this.alertIsVisible = false;
}
}
};

View File

@ -8,4 +8,4 @@ services:
ports:
- 8080:8080
volumes:
- ./2021-09-06_composition-19-vuex-starting-project/:/app
- ./2021-09-06_reuse-01-starting-setup/:/app