search
HomeWeb Front-endVue.jsComprehensive inventory of ref and reactive in vue3

I know if you have such doubts when using Vue3, "ref and rective can create a responsive object, how should I choose?", "Why does a responsive object lose its responsiveness after destructuring? How should it be handled? ?” Today we will take a comprehensive inventory of ref and reactive. I believe you will gain something different after reading it. Let’s learn together!

Comprehensive inventory of ref and reactive in vue3

reactive()

Basic usage

We can use it in Vue3 reactive() Create a responsive object or array:

import { reactive } from 'vue'

const state = reactive({ count: 0 })

This responsive object is actually a Proxy, Vue will use this Proxy Side effects are collected when the properties are accessed, and side effects are triggered when the properties are modified.

To use responsive state in component templates, you need to define and return it in the setup() function. [Related recommendations: vuejs video tutorial, web front-end development]

<script>
import { reactive } from &#39;vue&#39;

export default {  setup() {    const state = reactive({ count: 0 })    return {      state    }  }}
</script>

<template>
  <div>{{ state.count }}</div>
</template>

Of course, you can also use <script setup></script>,## Top-level imports and variable declarations in #

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools