refAPI的使用

2022/8/11 refAPI的使用Vue3ref

refAPI的使用

# refAPI的使用

注意 在模板里 vue会自动解包 原本是 content.value 而script标签里没有解包这个东西

<template>
  <div>{{ content }} <button @click="add">点击</button></div>
</template>

<script>
import { ref } from "vue";
export default {
  setup(props, { attrs, slots, emit }) {
   const content=ref(0)
    const add = () => {
      content.value++;
    };
    return {
      add,
      content,
    };
  },
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19