1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| <template>
| <h2>Manage Goals</h2>
| <input type="text" ref="goal" />
| <button @click="setGoal">Set Goal</button>
| <teleport to="body">
| <error-alert v-if="inputIsInvalid">
| <h2>Input is invalid!</h2>
| <p>Please enter at least a few characters...</p>
| <button @click="confirmError">Okay</button>
| </error-alert>
| </teleport>
| </template>
|
| <script>
| import ErrorAlert from './ErrorAlert.vue';
|
| export default {
| components: {
| ErrorAlert,
| },
| data() {
| return {
| inputIsInvalid: false,
| };
| },
| methods: {
| setGoal() {
| const enteredValue = this.$refs.goal.value;
| if (enteredValue === '') {
| this.inputIsInvalid = true;
| }
| },
| confirmError() {
| this.inputIsInvalid = false;
| },
| },
| };
| </script>
|
|