This repository has been archived on 2021-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
vuejs_course/2021-02-06 cmp-adv-01-start.../src/components/ManageGoals.vue

39 lines
894 B
Vue

<template>
<div>
<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 may not be empty</h2>
<button @click="resetErrorDialog">Ok</button>
</error-alert>
</teleport>
</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>