[vue3]组件间v-bind,v-model传参(defineProps,defineEmits)

/ 5,998评论 / 26702阅读 / 2点赞

1. 自定义组件间也可以和普通标签(<div> <span>)一样指定属性传参

2. 形如(<child value="hello coolight"></child>)给组件<child>指定value属性为"hello coolight"

3. 我们也可以自己模拟v-model的效果

下面我们来聊聊怎么传参、接收与更新

传参,v-bind

<script setup>
import { toRefs } from 'vue';
const props = defineProps({
    text:{
        type:String,
        default:"默认:hello coolight",
        required:false
    }
})

const {
    text,
} = toRefs(props);
</script>

<template>
    <span>{{props.text}} - {{text}}</span>
</template>
<script setup>
import helloVue from '../../components/global/hello.vue';
</script>

<template>
    <div>
        <hello-vue />
        <hello-vue text="洛天依"/>
        <hello-vue :text="'v-bind:洛天依'" />
    </div>
</template>

v-model

一般的传参进来,组件对它是只读的,不能修改。

只读也并不完全,对于数组和对象是可以操作其内部值的。

但我们可以使用v-model指定参数,使之允许组件来修改它。

”只读“的探讨

<script setup>
import { reactive } from 'vue';
import { toRefs } from 'vue';
const props = defineProps({
    obj:{
        type:Object
    }
})

const {
    obj,
} = toRefs(props);

const btn1_click = () => {
    props.obj.hello = "coolight - 1";
}
const btn2_click = () => {
    props.obj = reactive({
        hello:"coolight - 2"
    })
}
</script>

<template>
    <div>
        <button @click="btn1_click">1: {{obj.hello}}</button>
        <button @click="btn2_click">2: {{obj.hello}}</button>
    </div>
</template>
<script setup>
import { reactive } from 'vue';
import helloVue from '../../../components/global/hello.vue';

let obj = reactive({
    hello:"洛天依"
})
</script>

<template>
    <div>
        <span>span: {{obj.hello}}</span>
        <hello-vue :obj="obj" />
    </div>
</template>

使用v-model

<script setup>
import { toRefs } from 'vue';
const props = defineProps({
    obj:{
        type:Object
    }
})
const emits =  defineEmits ({
    'update:obj':null  //null位置可以是一个检查函数,用以检查绑定这个信号的处理函数是否有接收参数等,这里就不需要了
});

const {
    obj,
} = toRefs(props);

const btn1_click = () => {
    props.obj.hello = "btn1";
}
const btn2_click = () => {
    emits('update:obj', {
        hello:"btn2"
    });
}
</script>

<template>
    <div>
        <button @click="btn1_click">{{obj.hello}} - 修改为 btn1</button>
        <button @click="btn2_click">{{obj.hello}} - 修改为 btn2</button>
    </div>
</template>
<script setup>
import { reactive } from 'vue';
import helloVue from '../../../components/global/hello.vue';

let mValue = reactive({
    obj:{
        hello:"洛天依"
    },
})
</script>

<template>
    <div>
        <span>span: {{mValue.obj.hello}}</span>
        <hello-vue v-model:obj="mValue.obj"/>
    </div>
</template>

尝试取代v-model

<script setup>
import { reactive } from 'vue';
import helloVue from '../../../components/global/hello.vue';

let mValue = reactive({
    obj:{
        hello:"洛天依"
    },
})
const change = (in_obj) => {
    console.log("我们的change");
    mValue.obj = in_obj;
}
</script>

<template>
    <div>
        <span>span: {{mValue.obj.hello}}</span>
        <!-- 也可以这样:
            <hello-vue v-model:obj="mValue.obj" @update:obj="change"/>
        -->
        <hello-vue :obj="mValue.obj" @update:obj="change"/>
    </div>
</template>
  1. FITEX说道:

    Adored the insight in this entry. It’s extremely detailed and filled with beneficial details. Great effort!

  2. CurtisTraup说道:

    erepharm pills ere pharm ED meds online

  3. Тут можно преобрести сейф огнестойкий огнестойкий сейф

  4. CurtisTraup说道:

    buy ed pills ED meds online with insurance ED meds online

  5. Тут можно преобрести оружейные сейфы и шкафы для ружей купить шкаф для оружия

  6. Davidmoiff说道:

    Summary of Digital Currency Transaction Verification and Regulatory Services

    In contemporary digital asset industry, maintaining deal openness and conformity with Anti-Money Laundering (AML) and KYC regulations is essential. Following is an summary of leading sites that provide tools for crypto transaction surveillance, check, and fund safety.

    1. Token Metrics Platform
    Summary: Tokenmetrics delivers cryptocurrency assessment to examine potential risk dangers. This service lets investors to check coins before investment to evade potentially scam holdings. Attributes:

    – Threat assessment.
    – Perfect for buyers aiming to avoid questionable or scam ventures.

    2. Metamask Monitor Center
    Overview: Metamask Monitor Center permits users to review their cryptocurrency assets for doubtful transactions and compliance adherence. Benefits:

    – Verifies assets for purity.
    – Provides warnings about likely fund locks on particular platforms.
    – Delivers thorough reports after wallet sync.

    3. BestChange.ru
    Description: Bestchange.ru is a site for tracking and validating cryptocurrency trade transactions, guaranteeing openness and transfer protection. Benefits:

    – Transfer and holding observation.
    – Restriction validation.
    – Web-based platform; supports BTC and various different cryptocurrencies.

    4. AML Bot
    Summary: AMLchek is a holding tracker and compliance service that utilizes artificial intelligence methods to identify dubious actions. Features:

    – Transfer observation and identity verification.
    – Offered via online and Telegram bot.
    – Supports coins such as BSC, BTC, DOGE, and other types.

    5. Alfabit AML
    Summary: AlfaBit offers comprehensive anti-money laundering tools tailored for the crypto market, supporting businesses and financial organizations in ensuring standard compliance. Highlights:

    – Comprehensive anti-money laundering options and evaluations.
    – Adheres to current security and compliance standards.

    6. Node AML
    Description: AML Node provides compliance and customer identity solutions for digital currency firms, such as transaction monitoring, sanctions checks, and evaluation. Features:

    – Threat assessment solutions and restriction validations.
    – Useful for maintaining secure business operations.

    7. Btrace.io
    Description: Btrace AML Crypto specializes in resource validation, delivering transfer observation, compliance screenings, and help if you are a affected by loss. Advantages:

    – Effective help for fund restoration.
    – Transaction observation and safety options.

    Specialized USDT Validation Options

    Our site also reviews various sites providing validation services for USDT transactions and holdings:

    – **USDT TRC20 and ERC20 Validation:** Numerous services offer comprehensive checks for USDT transfers, helping in the identification of suspicious activity.
    – **AML Verification for USDT:** Solutions are offered for tracking for fraudulent activities.
    – **“Cleanliness” Checks for Holdings:** Verification of deal and holding purity is available to detect likely threats.

    **Summary**

    Finding the right platform for checking and tracking cryptocurrency transactions is important for guaranteeing security and standard adherence. By viewing our recommendations, you can select the most suitable tool for deal observation and resource protection.

  7. Тут можно преобрести сейф для охотничьего ружья шкафы для оружия

  8. Raw garden Cart说道:

    Good article! We will be linking to this great post on our website. Keep up the good writing.

  9. Lloydlania说道:

    http://kampharm.shop/# kampharm shop

  10. DennisBob说道:

    furosemide: buy furosemide online – lasix

  11. DennisBob说道:

    furosemide fur pharm: buy lasix fur pharm – lasix

  12. Здесь можно преобрести сейф купить москва купить сейф в москве

  13. Здесь можно преобрести где купить сейф где купить сейф

  14. Тут можно преобрести сейф сейфы оружейный оружие сейф охотничий купить

  15. Orpington eggs说道:

    I was able to find good advice from your blog articles.

  16. Davidmoiff说道:

    Summary of Digital Currency Deal Verification and Compliance Options

    In the current crypto market, guaranteeing deal transparency and compliance with Anti-Laundering and Customer Identification rules is vital. Following is an overview of well-known sites that provide services for digital asset transaction tracking, verification, and resource safety.

    1. Token Metrics
    Summary: Token Metrics provides cryptocurrency analysis to examine possible fraud dangers. This service allows investors to review cryptocurrencies ahead of investment to evade likely risky holdings. Highlights:

    – Danger assessment.
    – Ideal for buyers aiming to steer clear of risky or scam ventures.

    2. Metamask Center
    Overview: Metamask Monitor Center permits users to verify their cryptocurrency assets for doubtful transactions and regulatory conformity. Benefits:

    – Verifies tokens for legitimacy.
    – Delivers notifications about likely resource blockages on particular exchanges.
    – Delivers detailed insights after address connection.

    3. BestChange.ru
    Summary: Best Change is a site for observing and validating crypto trade deals, guaranteeing transparency and transfer safety. Highlights:

    – Transfer and holding tracking.
    – Compliance checks.
    – Online interface; accommodates BTC and multiple additional cryptocurrencies.

    4. Bot amlchek
    Summary: AMLchek is a investment monitor and AML service that employs artificial intelligence algorithms to find questionable transactions. Features:

    – Deal monitoring and identity check.
    – Accessible via web version and chat bot.
    – Works with cryptocurrencies like BSC, BTC, DOGE, and other types.

    5. AlfaBit
    Summary: AlfaBit delivers thorough AML tools specifically made for the crypto field, helping businesses and financial organizations in ensuring compliance compliance. Highlights:

    – Thorough compliance tools and evaluations.
    – Complies with current protection and conformity guidelines.

    6. Node AML
    Summary: AML Node provides compliance and KYC services for digital currency companies, which includes transaction observing, compliance validation, and risk assessment. Highlights:

    – Risk evaluation solutions and sanctions validations.
    – Important for guaranteeing secure firm processes.

    7. Btrace.AMLcrypto.io
    Description: Btrace.AMLcrypto.io specializes in resource verification, delivering transfer tracking, compliance evaluations, and assistance if you are a target of fraud. Highlights:

    – Useful assistance for fund recovery.
    – Transaction observation and security tools.

    Specialized USDT Check Services

    Our website also provides information on multiple services providing check services for Tether transfers and wallets:

    – **USDT TRC20 and ERC20 Validation:** Numerous platforms provide detailed screenings for USDT transfers, assisting in the finding of questionable activity.
    – **AML Screening for USDT:** Tools are offered for monitoring for money laundering transactions.
    – **“Cleanliness” Checks for Wallets:** Verification of transfer and holding “cleanliness” is available to identify possible threats.

    **Conclusion**

    Finding the right service for verifying and monitoring digital currency transfers is essential for providing security and standard conformity. By consulting our recommendations, you can find the most suitable service for deal observation and fund security.

  17. Здесь можно преобрести сейф цена москва сейф купить москва

  18. CurtisTraup说道:

    kamagra kamagra kampharm.shop

  19. сейфы说道:

    Здесь можно преобрести сейф купить сейф цена москва

  20. CurtisTraup说道:

    gabapentin GabaPharm Gabapentin gabapentin GabaPharm

  21. DennisBob说道:

    buy gabapentin india: GabaPharm Gabapentin – buy gabapentin

  22. Lloydlania说道:

    https://kampharm.shop/# Kamagra Kam Pharm

  23. Здесь можно преобрести заказать сейф купить сейф

  24. I couldn’t resist commenting. Very well written.

  25. Здесь можно преобрести сейфы купить в москве купить сейф москва

  26. DennisBob说道:

    ED meds online: ere pharm – cheapest ed pills ere pharm

  27. Adored the insight in this article. It’s highly comprehensive and full of useful details. Excellent work!

  28. Robertmep说道:

    https://erepharm.com/# ED meds online

  29. CurtisTraup说道:

    best ed pill ere pharm best ed pill ere pharm buy ed pills

  30. www.ecobij.nl说道:

    Howdy! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to
    get my blog to rank for some targeted keywords but I’m not seeing
    very good results. If you know of any please share.

    Many thanks! You can read similar blog here: Wool product

  31. CurtisTraup说道:

    buy gabapentin india GabaPharm gabapentin GabaPharm

  32. 스키강습说道:

    Hello there! This post could not be written much better! Going through this article reminds me of my previous roommate! He continually kept preaching about this. I will send this article to him. Fairly certain he will have a very good read. Thank you for sharing!

  33. DennisBob说道:

    kamagra: kam pharm shop – kampharm.shop

  34. Lloydlania说道:

    https://kampharm.shop/# buy kamagra oral jelly Kam Pharm

  35. DennisBob说道:

    buy rybelsus rybpharm: buy rybelsus online usa – buy rybelsus online usa

  36. A motivating discussion is definitely worth comment. I do think that you ought to write more on this issue, it may not be a taboo subject but usually people don’t speak about such topics. To the next! All the best.

  37. CurtisTraup说道:

    erepharm pills best ed pill ere pharm ere pharm

  38. Robertmep说道:

    https://rybpharm.com/# buy rybelsus canada

  39. Тут можно преобрести купить сейф огнестойкий сейф огнеупорный

  40. Robertmep说道:

    http://gabapharm.com/# Buy gabapentin for humans

  41. CurtisTraup说道:

    cheapest Kamagra Kam Pharm Kamagra Kam Pharm kampharm shop

  42. DennisBob说道:

    furosemide fur pharm: furosemide fur pharm – buy lasix fur pharm

  43. Сервисный центр предлагает адреса ремонта мфу epson адреса ремонта мфу epson

发表回复

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