ref的简单使用

发布时间 2023-10-21 16:21:24作者: mingBolg
<script setup>
    import { ref } from 'vue'
      const msg = ref(1)
      const clickMsg = () =>{ msg.value++; console.log('+++')}

      const clickMsgjj = () =>{ msg.value--; console.log('---')}
 
</script>

<template>
   <div>{{ msg }}</div><br>
   <button @click="clickMsg" >按钮++</button>
   <button @click="clickMsgjj" >按钮--</button>
</template>

<style scoped>
 
</style>

ref 可以让数据成为响应式