Skip to content
On this page

useComputed

基本使用

解决计算属性不可传参的问题

2 2 2 2 带计算属性执行次数:1
vue
<template>
{{doubleCount(1)}} 
{{doubleCount(1)}}
{{doubleCount(1)}}
{{doubleCount(1)}}
带计算属性执行次数:{{count}}
</template>

<script setup lang="ts">
import { useComputed } from 'knot-vue'
import {ref} from 'vue'

const count = ref(0)
const doubleCount = useComputed((num) => {
    console.log("执行第"+count.value+"")
    count.value++
    return 2 * num
})
</script>

Released under the MIT License.