lesson 116: add an error dialog

This commit is contained in:
Andreas Zweili 2021-02-07 17:24:21 +01:00
parent 33b90927a1
commit dcd02c7693
2 changed files with 49 additions and 1 deletions

View File

@ -0,0 +1,18 @@
<template>
<dialog open>
<slot></slot>
</dialog>
</template>
<style scoped>
dialog {
margin: 0;
position: fixed;
top: 20vh;
left: 30%;
width: 40%;
background-color: white;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
padding: 1rem;
}
</style>

View File

@ -1,6 +1,36 @@
<template>
<div>
<h2>Manage Goals</h2>
<input type="text" />
<input type="text" ref="goal" />
<button @click="setGoal">Set Goal</button>
<error-alert v-if="inputIsInvalid">
<h2>Input may not be empty</h2>
<button @click="resetErrorDialog">Ok</button>
</error-alert>
</div>
</template>
<script>
import ErrorAlert from "./ErrorAlert";
export default {
components: {
ErrorAlert,
},
data() {
return {
inputIsInvalid: false,
};
},
methods: {
setGoal() {
const enteredValue = this.$refs.goal.value;
if (enteredValue === "") {
this.inputIsInvalid = true;
}
},
resetErrorDialog() {
this.inputIsInvalid = false;
},
},
};
</script>