[Vue3]在setup中声明响应式数据(ref,reactive)

/ 61,876评论 / 350283阅读 / 2点赞

响应式数据是vue的一大亮点,下面我们来聊聊如何声明响应式数据

直接声明变量

<script setup>
let num = 0;
const clickFun = () => {
    console.log("num:", ++num);
}
</script>

<template>
    <div style="display:flex;flex-direction: column;">
        <span>num : {{num}}</span>
        <button @click="clickFun()">修改</button>
    </div>
</template>

ref(基本数据类型)

<script setup>
import { ref } from 'vue';

let num = 0;
let refNum = ref(0);
console.log("refNum:", refNum);
console.log("refNum.value", refNum.value);

const clickFun = () => {
    console.log("num:", ++num);
    console.log("refNum.value:" , ++refNum.value);
}
</script>

<template>
    <div style="display:flex;flex-direction: column;">
        <span>num : {{num}}</span>
        <span>refNum : {{refNum}}</span>
        <button @click="clickFun()">修改</button>
    </div>
</template>

reactive(对象)

<script setup>
import { ref,reactive } from 'vue';

let num = 0;
let refNum = ref(0);
let rea = reactive({
    num:0
});

console.log("refNum:", refNum);
console.log("refNum.value", refNum.value);
console.log("rea", rea);

const clickFun = () => {
    console.log("num:", ++num);
    console.log("refNum.value:" , ++refNum.value);
    console.log("rea.num:", ++rea.num);
}

</script>

<template>
    <div style="display:flex;flex-direction: column;">
        <span>num : {{num}}</span>
        <span>refNum : {{refNum}}</span>
        <span>rea.num : {{rea.num}}</span>
        <button @click="clickFun()">修改</button>
    </div>
</template>
  1. 아이 슬롯
    Xiao Jing은 더 이상 감히 아무 말도하지 않았고 사실 그는 상당히 불편했습니다.

  2. 다바오 관광说道:

    How To Get Your First Credit Card With No History – 3 Steps That Don’t Fail 다바오 관광

  3. Lazrblm说道:

    Здравствуйте!
    Мы можем предложить дипломы любой профессии по приятным тарифам.
    dachkanews.ru/kupite-diplom-dlya-vashego-budushhego/

  4. Jamesjer说道:

    paxlovid pill: buy paxlovid online – paxlovid covid

  5. read more说道:

    Hello, I do believe your site could be having browser compatibility issues. Whenever I look at your web site in Safari, it looks fine however when opening in I.E., it’s got some overlapping issues. I simply wanted to provide you with a quick heads up! Apart from that, excellent blog.

  6. Michaelphime说道:

    AC Milan https://italy.milan-ar.com is one of the most successful and decorated football clubs in the world.

  7. Charlesimify说道:

    Ремонт плоской кровли https://remontiruem-krovly.ru в Москве, цена работы за 1 м?. Прайс лист на работы под ключ, отзывы и фото.

  8. StevenSof说道:

    Thai Company Directory https://thaicorporates.com List of companies and business information.

  9. 비아그라 효능 25mg으로도 효과 있나?

    비아그라 25mg 용량의 효과: 충분한 성기능 향상을 위한 올바른 선택

  10. ThomasInace说道:

    https://ciprodelivery.pro/# ciprofloxacin order online

  11. Jamesjer说道:

    buy cipro online without prescription: ciprofloxacin generic price – buy cipro online canada

  12. TimothySkymn说道:

    Real Madrid’s https://spain.real-madrid-ar.com history goes back more than a century. The club was founded in 1902 by a group of football enthusiasts led by Juan Padilla

  13. MichaelLix说道:

    FC Bayern Munich (Munich) https://germany.bayern-munchen-ar.com is one of the most famous and recognized football clubs in Germany and Europe

  14. RandallWhirm说道:

    Arsenal https://england.arsenal-ar.com is one of the most famous and successful football clubs in the history of English football.

  15. Xazricx说道:

    Привет!
    Официальное получение диплома техникума с упрощенным обучением в Москве
    arusak-diploms-srednee.ru/kupit-attestat-za-11-klass В 

  16. Manrpgf说道:

    Добрый день!
    Купить документ института
    asxdiplomik24.ru/kupit-diplom-sankt-peterburg

  17. I’m more than happy to discover this site. I need to to thank you for your time due to this fantastic read!! I definitely really liked every bit of it and i also have you bookmarked to look at new things on your website.

  18. 슬롯 보증 사이트
    앙드레는 마치 승리의 새벽을 본 듯 눈썹을 살짝 치켜올렸다.

  19. Jamesjer说道:

    amoxicillin no prescription: azithromycin amoxicillin – where can you get amoxicillin

  20. ThomasInace说道:

    http://ciprodelivery.pro/# ciprofloxacin 500mg buy online

  21. Winning At Slot Machines – Slot Machine Cheat Secrets 소녀 에볼루션 티어표

  22. 다바오 치안说道:

    Bad Credit Should Not Stop You Getting If You Want A Loan Today 다바오 치안

  23. ThomasInace说道:

    http://doxycyclinedelivery.pro/# doxycycline 100mg tablets nz

  24. ThomasInace说道:

    https://doxycyclinedelivery.pro/# doxycycline capsules 40 mg

  25. Dnrtzap说道:

    Привет, друзья!
    Заказать документ института вы имеете возможность в нашем сервисе.
    ast-diplomy24.ru/kupit-diplom-nizhnij-novgorod
    Успешной учебы!

  26. ThomasInace说道:

    http://ciprodelivery.pro/# antibiotics cipro

  27. ThomasInace说道:

    https://paxloviddelivery.pro/# Paxlovid buy online

  28. Lariorqoy说道:

    Диплом техникума купить официально с упрощенным обучением в Москве
    diplomasx.com/kupit-diplom-moskva

  29. Jamesjer说道:

    amoxicillin 800 mg price: how to get amoxicillin – buy cheap amoxicillin

  30. Jamesjer说道:

    buying clomid tablets: order clomid – where to buy generic clomid

  31. Yreflil说道:

    Привет, друзья!
    Заказать диплом о высшем образовании.
    http://www.soft-clouds.com/blogs/96403/??????????-???????????-????-??????-?-????????-?????-?????-???????
    Успехов в учебе!

  32. Top 5 Ways To Obtain Traffic As Part Of Your Website Today 백링크 구매
    (muabanthuenha.com)

  33. ThomasInace说道:

    https://doxycyclinedelivery.pro/# doxycycline 10mg price

  34. Jamesjer说道:

    doxycycline india buy: buy doxycycline tablets 100mg – doxycycline prescription canada

  35. geocupss.com说道:

    No Credit Score Assessment Bank Accounts 급전 (geocupss.com)

  36. Lazrwwj说道:

    Здравствуйте!
    Мы можем предложить дипломы любой профессии по приятным ценам.
    isnw.ru/2024/06/30/купить-диплом-иргупс/

  37. Cazrlzr说道:

    Привет, друзья!
    Мы готовы предложить документы ВУЗов, которые расположены в любом регионе Российской Федерации. Вы можете приобрести качественно напечатанный диплом от любого заведения, за любой год, включая документы СССР. Дипломы и аттестаты выпускаются на бумаге самого высокого качества. Это дает возможности делать государственные дипломы, которые невозможно отличить от оригинала. Документы заверяются всеми требуемыми печатями и штампами.
    c904581v.beget.tech/2024/07/09/nizkie-ceny-i-prekrasnoe-kachestvo-pokupay-dokumenty-onlayn.html

  38. men kurta pajama说道:

    Nice post. I learn something new and challenging on websites I stumbleupon on a daily basis. It’s always helpful to read through content from other writers and practice a little something from other sites.

  39. KeithPex说道:

    FC Barcelona https://spain.fc-barcelona-ar.com is undoubtedly one of the most famous and well-known football clubs in the world.

  40. ThomasInace说道:

    http://ciprodelivery.pro/# ciprofloxacin mail online

  41. Bank Of America Will Forgive Principal On Certain Loans 다바오 다운로드

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注