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

/ 53,976评论 / 301258阅读 / 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. Davidfrify说道:

    п»їcytotec pills online buy cytotec over the counter cytotec online

  2. WilliamRen说道:

    https://nolvadex.life/# does tamoxifen cause menopause

  3. w-495.ru说道:

    москва психологическая помощь w-495.ru

  4. Davidfrify说道:

    tamoxifen cyp2d6 what is tamoxifen used for tamoxifen benefits

  5. RandallGuesE说道:

    lipinpril: lisinopril price uk – order lisinopril

  6. Scottvaw说道:

    Understanding COSC Accreditation and Its Importance in Watchmaking
    COSC Validation and its Rigorous Standards
    Controle Officiel Suisse des Chronometres, or the Controle Officiel Suisse des Chronometres, is the authorized Switzerland testing agency that verifies the precision and precision of timepieces. COSC validation is a symbol of excellent craftsmanship and trustworthiness in chronometry. Not all timepiece brands follow COSC validation, such as Hublot, which instead sticks to its own stringent standards with mechanisms like the UNICO calibre, attaining equivalent precision.

    The Art of Precision Chronometry
    The central mechanism of a mechanized timepiece involves the mainspring, which delivers energy as it loosens. This system, however, can be prone to environmental elements that may impact its precision. COSC-certified movements undergo demanding testing—over 15 days in various circumstances (5 positions, three temperatures)—to ensure their resilience and reliability. The tests assess:

    Mean daily rate accuracy between -4 and +6 secs.
    Mean variation, peak variation rates, and impacts of thermal variations.
    Why COSC Validation Is Important
    For watch enthusiasts and collectors, a COSC-certified watch isn’t just a item of technology but a proof to lasting quality and accuracy. It signifies a timepiece that:

    Presents excellent dependability and accuracy.
    Ensures guarantee of superiority across the complete design of the watch.
    Is likely to maintain its worth more effectively, making it a wise choice.
    Well-known Timepiece Brands
    Several well-known manufacturers prioritize COSC accreditation for their timepieces, including Rolex, Omega, Breitling, and Longines, among others. Longines, for instance, presents collections like the Record and Soul, which showcase COSC-certified mechanisms equipped with advanced substances like silicon balance springs to enhance durability and efficiency.

    Historic Context and the Evolution of Timepieces
    The concept of the timepiece dates back to the need for precise chronometry for navigational at sea, highlighted by John Harrison’s work in the eighteenth cent. Since the official foundation of Controle Officiel Suisse des Chronometres in 1973, the validation has become a yardstick for evaluating the accuracy of high-end watches, sustaining a tradition of excellence in watchmaking.

    Conclusion
    Owning a COSC-accredited timepiece is more than an aesthetic selection; it’s a commitment to quality and accuracy. For those valuing accuracy above all, the COSC accreditation provides peace of mind, ensuring that each accredited watch will perform reliably under various circumstances. Whether for individual contentment or as an investment decision, COSC-validated timepieces distinguish themselves in the world of horology, carrying on a tradition of careful timekeeping.

  7. WilliamRen说道:

    http://lisinopril.network/# lisinopril 10 mg daily

  8. Marcelcrolf说道:

    https://mexicoph24.life/# purple pharmacy mexico price list

  9. Earnestfemia说道:

    Сегодня, когда диплом становится началом удачной карьеры в любом направлении, многие стараются найти максимально быстрый путь получения образования. Наличие документа об образовании трудно переоценить. Ведь диплом открывает дверь перед каждым человеком, желающим начать профессиональную деятельность или учиться в ВУЗе.
    В данном контексте наша компания предлагает быстро получить этот необходимый документ. Вы сможете приобрести диплом, что становится отличным решением для человека, который не смог завершить образование, утратил документ или желает исправить плохие оценки. Все дипломы изготавливаются с особой тщательностью, вниманием к мельчайшим деталям. На выходе вы получите полностью оригинальный документ.
    Преимущества такого подхода заключаются не только в том, что вы оперативно получите свой диплом. Весь процесс организован удобно, с профессиональной поддержкой. Начав от выбора подходящего образца документа до консультации по заполнению личной информации и доставки по стране — все находится под полным контролем качественных специалистов.
    Для всех, кто ищет быстрый способ получить необходимый документ, наша компания может предложить отличное решение. Приобрести диплом – значит избежать продолжительного обучения и сразу перейти к важным целям, будь то поступление в университет или начало карьеры.

    https://diploman-rossiya.com

  10. RickyAlage说道:

    medication from mexico pharmacy cheapest mexico drugs mexican pharmacy

  11. Pedropaite说道:

    mexican pharmacy: mexico pharmacy – mexican rx online

  12. Scottvaw说道:

    Understanding COSC Validation and Its Importance in Horology
    COSC Accreditation and its Strict Criteria
    Controle Officiel Suisse des Chronometres, or the Controle Officiel Suisse des Chronometres, is the authorized Switzerland testing agency that certifies the precision and precision of wristwatches. COSC accreditation is a sign of quality craftsmanship and reliability in timekeeping. Not all watch brands follow COSC validation, such as Hublot, which instead adheres to its proprietary strict standards with movements like the UNICO calibre, reaching equivalent accuracy.

    The Art of Exact Timekeeping
    The core system of a mechanized watch involves the mainspring, which delivers energy as it loosens. This system, however, can be vulnerable to external factors that may affect its precision. COSC-certified mechanisms undergo rigorous testing—over 15 days in various circumstances (5 positions, three temperatures)—to ensure their durability and dependability. The tests assess:

    Average daily rate accuracy between -4 and +6 secs.
    Mean variation, highest variation rates, and effects of temperature changes.
    Why COSC Accreditation Is Important
    For timepiece enthusiasts and connoisseurs, a COSC-accredited watch isn’t just a piece of tech but a testament to lasting excellence and precision. It symbolizes a watch that:

    Provides exceptional dependability and precision.
    Offers guarantee of superiority across the whole design of the timepiece.
    Is probable to hold its value more efficiently, making it a wise choice.
    Well-known Chronometer Brands
    Several famous manufacturers prioritize COSC certification for their watches, including Rolex, Omega, Breitling, and Longines, among others. Longines, for instance, provides collections like the Archive and Soul, which highlight COSC-validated movements equipped with innovative substances like silicon balance suspensions to boost resilience and performance.

    Historical Background and the Evolution of Timepieces
    The concept of the chronometer dates back to the need for exact chronometry for navigation at sea, emphasized by John Harrison’s work in the eighteenth century. Since the formal foundation of Controle Officiel Suisse des Chronometres in 1973, the validation has become a standard for assessing the accuracy of high-end timepieces, continuing a tradition of excellence in horology.

    Conclusion
    Owning a COSC-validated watch is more than an aesthetic selection; it’s a commitment to excellence and accuracy. For those appreciating precision above all, the COSC accreditation provides peace of thoughts, ensuring that each certified timepiece will function reliably under various conditions. Whether for individual contentment or as an investment decision, COSC-accredited timepieces stand out in the world of watchmaking, maintaining on a legacy of meticulous timekeeping.

  13. Michaelsew说道:

    http://mexicoph24.life/# mexican online pharmacies prescription drugs

  14. StevenSen说道:

    canadian pharmacy uk delivery: Prescription Drugs from Canada – pharmacy canadian

  15. RickyAlage说道:

    online pharmacy india indian pharmacy fast delivery buy prescription drugs from india

  16. Marcelcrolf说道:

    https://canadaph24.pro/# legit canadian pharmacy

  17. Pedropaite说道:

    mexican drugstore online: Online Pharmacies in Mexico – buying prescription drugs in mexico

  18. StevenSen说道:

    canadian pharmacy no rx needed: Licensed Canadian Pharmacy – canadian online pharmacy

  19. Marcelcrolf说道:

    http://canadaph24.pro/# online canadian drugstore

  20. Lazaroslump说道:

    Закажите SEO продвижение сайта https://seo116.ru/ в Яндекс и Google под ключ в Москве и по всей России от экспертов. Увеличение трафика, рост клиентов, онлайн поддержка. Комплексное продвижение сайтов с гарантией.

发表回复

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