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-09-04_composition-assi.../src/App.vue

61 lines
1.3 KiB
Vue
Raw Normal View History

2021-09-04 11:28:31 +02:00
<template>
<h2>My Course Goal</h2>
<!-- Task 1: Output your main course goal with help of the composition API -->
<!-- Don't hardcode it into the template, instead hardcode it into the JS code -->
2021-09-04 11:57:57 +02:00
<h3 v-if="Goal.visibility">{{ courseGoal }}</h3>
2021-09-04 11:28:31 +02:00
<!-- Task 2: Toggle (show/ hide) the goal with help of the button -->
2021-09-04 11:53:07 +02:00
<button @click="toggleGoal">Toggle Goal</button>
2021-09-04 11:28:31 +02:00
<!-- Task 3: Manage data in three ways -->
<!-- => Separate refs -->
<!-- => Ref Object -->
<!-- => Reactive Object -->
<!-- Task 4: Also solve the assignment with the Options API -->
</template>
<script>
2021-09-04 12:00:15 +02:00
//import { ref } from 'vue';
import { reactive } from 'vue';
2021-09-04 11:53:07 +02:00
2021-09-04 11:28:31 +02:00
export default {
2021-09-04 11:53:07 +02:00
setup() {
const courseGoal = 'Something is written here';
2021-09-04 11:57:57 +02:00
//const showGoal = ref(false);
2021-09-04 12:00:15 +02:00
const Goal = reactive({
2021-09-04 11:57:57 +02:00
visibility: false
});
2021-09-04 11:53:07 +02:00
2021-09-04 11:57:57 +02:00
// ref way
//function toggleGoal() {
// showGoal.value = !showGoal.value;
// console.log(showGoal.value);
//}
// ref object way
2021-09-04 12:00:15 +02:00
//function toggleGoal() {
// Goal.value.visibility = !Goal.value.visibility;
//}
// reactive way
2021-09-04 11:53:07 +02:00
function toggleGoal() {
2021-09-04 12:00:15 +02:00
Goal.visibility = !Goal.visibility;
2021-09-04 11:53:07 +02:00
}
return {
courseGoal,
2021-09-04 11:57:57 +02:00
Goal,
2021-09-04 11:53:07 +02:00
toggleGoal
};
}
};
2021-09-04 11:28:31 +02:00
</script>
<style>
html {
font-family: sans-serif;
}
body {
margin: 3rem;
text-align: center;
}
2021-09-04 11:53:07 +02:00
</style>