"Vue.js Composition API"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 3개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;Composition API
;Vue.js Composition API
;Vue.js 컴포지션 API
 
* Reactivity API:.[[ref()]],  [[reactive()]]
* Lifecycle Hooks: [[onMounted()]], [[onUnmounted()]]
* Dependency Injection: [[provide()]],  [[inject()]]


<syntaxhighlight lang='html'>
<syntaxhighlight lang='html'>
25번째 줄: 30번째 줄:
</syntaxhighlight>
</syntaxhighlight>


==computed==
<syntaxhighlight lang='html'>
<script setup>
import { reactive, computed } from 'vue'
const author = reactive({
  name: 'John Doe',
  books: [
    'Vue 2 - Advanced Guide',
    'Vue 3 - Basic Guide',
    'Vue 4 - The Mystery'
  ]
})
// a computed ref
const publishedBooksMessage = computed(() => {
  return author.books.length > 0 ? 'Yes' : 'No'
})
</script>
<template>
  <p>Has published books:</p>
  <span>{{ publishedBooksMessage }}</span>
</template>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2023년 10월 17일 (화) 14:24 기준 최신판

1 개요[ | ]

Vue.js Composition API
Vue.js 컴포지션 API
<script setup>
import { ref, onMounted } from 'vue'

// reactive state
const count = ref(0)

// functions that mutate state and trigger updates
function increment() {
  count.value++
}

// lifecycle hooks
onMounted(() => {
  console.log(`The initial count is ${count.value}.`)
})
</script>

<template>
  <button @click="increment">Count is: {{ count }}</button>
</template>

2 computed[ | ]

<script setup>
import { reactive, computed } from 'vue'

const author = reactive({
  name: 'John Doe',
  books: [
    'Vue 2 - Advanced Guide',
    'Vue 3 - Basic Guide',
    'Vue 4 - The Mystery'
  ]
})

// a computed ref
const publishedBooksMessage = computed(() => {
  return author.books.length > 0 ? 'Yes' : 'No'
})
</script>

<template>
  <p>Has published books:</p>
  <span>{{ publishedBooksMessage }}</span>
</template>

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}