ref,computed 用法
原创
©著作权归作者所有:来自51CTO博客作者wg_iGBFcBFB的原创作品,请联系作者获取转载授权,否则将追究法律责任
ref,computed 用法
<template>
<div>
<h1>{{count}}</h1>
<h1>{{double}}</h1>
<button @click="increase">+1</button>
</div>
</template>
<script lang="ts">
import { ref,computed } from 'vue';
export default {
name: 'App',
setup(){
const count = ref(0)
const double = computed(()=>{
return count.value * 2
})
const increase = () => {
count.value ++
}
return {
count,
double,
increase
}
}
};
</script>