export default {
data() {
return {
counter: 0,
books: [],
};
},
methods: {
increment() {
this.counter++;
},
addBook(title, author) {
this.books.push({ title, author });
},
},
computed: {
firstBook() {
return this.books[0];
}
}
mounted() {
console.log('애플리케이션이 마운트 되었습니다!');
},
};
Composition API는 옵션(data, methods, ...)을 선언하는 대신 가져온 함수(ref, onMounted, ...)를 사용하여 Vue 컴포넌트를 작성할 수 있는 API 세트를 말한다.
<script setup>
import { onMounted, reactive, ref } from 'vue';
// count 관련 로직 -1
const counter = ref(0);
const increment = () => {
counter.value++;
};
// books 관련 로직 -2
const books = reactive([]);
const addBook = (title, author) => {
books.push({ title, author });
};
onMounted(() => {
console.log('애플리케이션이 마운트 되었습니다!');
});
</script>