28 <script setup lang="ts"> import { useCounter } from '@/compositions/useCounter' const { count, increment, decrement } = useCounter(0) </script> <template> カウント: {{ count }} <button @click="increment">increment</button> <button @click="decrement">decrement</button> </template> Sample.vue import { ref } from 'vue' export function useCounter(initialValue = 0) { const count = ref(initialValue) const increment = () => count.value++ const decrement = () => count.value-- return { count, increment, decrement } } useCounter.ts <script setup lang="ts"> import { ref } from 'vue' const count = ref(0) const increment = () => count.value++ const decrement = () => count.value-- </script> <template> COUNT: {{ count }} <button @click="increment">increment</button> <button @click="decrement">decrement</button> </template> Sample.vue コンポーザブル関数として切り出し Before After 状態とロジックを使える