reactive, toRefs 用法

<template>
      <div>
          <h1>{{count}}</h1>
          <h1>{{double}}</h1>
          <button @click="increase">+1</button>
      </div>
</template>

<script lang="ts"> 
import { ref,computed,reactive, toRefs } from ‘vue‘;    
interface DataProps {
  count:number;
  double:number;
  increase: () => void;
}
export default {
  name: ‘App‘,
  setup(){
 
    const data:DataProps = reactive({
      count:0,
      increase:() => { data.count ++ },
      double:computed(() =>  data.count * 2 )
    })

    const refData  = toRefs(data)
    return {
      ...refData 
    }
  
  } 
};
</script>

reactive, toRefs 用法

上一篇:常见面试题:Object类中有哪些方法,分别有什么作用?


下一篇:添加公告栏时钟