vue3 ref<>
时间: 2023-10-17 07:58:52 浏览: 38
Vue 3 introduces a new function called `ref()` which is used to create a reactive reference to a value. It is a replacement for the `data` property in Vue 2.
To use `ref()`, you need to import it from the `vue` package. Here's an example of how to use it:
```
import { ref } from 'vue';
const value = ref(0);
console.log(value.value); // 0
value.value = 1;
console.log(value.value); // 1
```
In the above example, we create a reactive reference called `value` using `ref(0)`. The initial value of the reference is set to 0. To access the value, we use `value.value`. We can also modify the value by assigning a new value to `value.value`. Vue will automatically update any components that are using this reference whenever the value changes.
Note that `ref()` returns an object with a property called `value`. This is because Vue 3 separates the reactivity from the actual value, allowing you to access and modify the value through the `value` property.