Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created May 2, 2022 17:07
Show Gist options
  • Save JeffreyWay/3ce3c6470adf6a1bf599a772e6a6b59b to your computer and use it in GitHub Desktop.
Save JeffreyWay/3ce3c6470adf6a1bf599a772e6a6b59b to your computer and use it in GitHub Desktop.
Learn Vue 3, Step by Step - Episode 6, Component Props
import AppButton from "./AppButton.js";
export default {
components: {
'app-button': AppButton
}
};
export default {
template: `
<button
:class="{
'border rounded px-5 py-2 disabled:cursor-not-allowed': true,
'bg-blue-600 hover:bg-blue-700': type === 'primary',
'bg-purple-200 hover:bg-purple-400': type === 'secondary',
'bg-gray-200 hover:bg-gray-400': type === 'muted',
'is-loading': processing
}"
:disabled="processing"
>
<slot />
</button>
`,
props: {
type: {
type: String,
default: 'primary'
},
processing: {
type: Boolean,
default: false
}
}
}
<!doctype html>
<html lang="en" class="h-full">
<head>
<meta charset="UTF-8">
<title>Episode 5: Extract Components to Their Own Files</title>
<script src="https://unpkg.com/vue@3"></script>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@keyframes spinner {
to {transform: rotate(360deg);}
}
.is-loading { color: transparent; }
.is-loading:before {
content: '';
box-sizing: border-box;
position: absolute;
top: 50%;
left: 50%;
width: 20px;
height: 20px;
margin-top: -10px;
margin-left: -10px;
border-radius: 50%;
border: 2px solid #ccc;
border-top-color: #000;
animation: spinner .6s linear infinite;
}
</style>
</head>
<body class="h-full grid place-items-center">
<div id="app">
<app-button :processing="true">Submit</app-button>
</div>
<script type="module">
import App from "./js/components/App.js";
Vue.createApp(App).mount('#app');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment