ref,computed 用法

时间:2021-08-30 05:18:08   收藏:0   阅读:2

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>

原文:https://www.cnblogs.com/eric-share/p/15198681.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!