add an example project for reusing composition API code
This commit is contained in:
parent
11a3800d3a
commit
19e3b617fd
|
@ -0,0 +1,3 @@
|
||||||
|
> 1%
|
||||||
|
last 2 versions
|
||||||
|
not dead
|
|
@ -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'
|
||||||
|
}
|
||||||
|
}
|
|
@ -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?
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"singleQuote": true
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,5 @@
|
||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
'@vue/cli-plugin-babel/preset'
|
||||||
|
]
|
||||||
|
}
|
|
@ -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 |
|
@ -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>
|
|
@ -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>
|
|
@ -0,0 +1,28 @@
|
||||||
|
<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 './UserAlert.vue';
|
||||||
|
import useAlert from '../hooks/alert';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
UserAlert
|
||||||
|
},
|
||||||
|
setup() {
|
||||||
|
const [alertIsVisible, showAlert, hideAlert] = useAlert();
|
||||||
|
return {
|
||||||
|
alertIsVisible,
|
||||||
|
showAlert,
|
||||||
|
hideAlert
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -0,0 +1,28 @@
|
||||||
|
<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 './UserAlert.vue';
|
||||||
|
import useAlert from '../hooks/alert';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
UserAlert
|
||||||
|
},
|
||||||
|
setup() {
|
||||||
|
const [alertIsVisible, showAlert, hideAlert] = useAlert();
|
||||||
|
return {
|
||||||
|
alertIsVisible,
|
||||||
|
showAlert,
|
||||||
|
hideAlert
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -0,0 +1,73 @@
|
||||||
|
<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'],
|
||||||
|
setup(_, context) {
|
||||||
|
function closeDialog() {
|
||||||
|
context.emit('close');
|
||||||
|
}
|
||||||
|
|
||||||
|
return { closeDialog };
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</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>
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
export default function useAlert() {
|
||||||
|
const alertIsVisible = ref(false);
|
||||||
|
|
||||||
|
function showAlert() {
|
||||||
|
alertIsVisible.value = true;
|
||||||
|
}
|
||||||
|
function hideAlert() {
|
||||||
|
alertIsVisible.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [alertIsVisible, showAlert, hideAlert];
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { createApp } from 'vue';
|
||||||
|
|
||||||
|
import App from './App.vue';
|
||||||
|
|
||||||
|
const app = createApp(App)
|
||||||
|
|
||||||
|
app.mount('#app');
|
|
@ -8,4 +8,4 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- 8080:8080
|
- 8080:8080
|
||||||
volumes:
|
volumes:
|
||||||
- ./2021-09-06_reuse-01-starting-setup/:/app
|
- ./2021-09-06_reuse-04-composition-api-starting-project/:/app
|
||||||
|
|
Reference in New Issue