国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue3中emit(‘update:modelValue‘)使用

這篇具有很好參考價(jià)值的文章主要介紹了vue3中emit(‘update:modelValue‘)使用。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

<template>
  <TestCom v-model="test1" v-model:test2="test2"></TestCom>
  <h1>{{test1}}測(cè)試1</h1>
  <h1>{{test2}}測(cè)試2</h1>
</template>

<script setup>
import { ref, reactive } from 'vue'
const test1 = ref('')
const test2 = ref('')
</script>

子(setup語(yǔ)法糖)

<template>
	<input v-model="message" @input="changeInfo(message)" />
	<input v-model="message2" @input="changeInfo2(message2)" />
</template>
<script setup>
import { ref, watch } from 'vue';
// 此處引入
const emit = defineEmits(['update:modelValue', 'update:test2'])
const props = defineProps({
	// 父組件 v-model 沒(méi)有指定參數(shù)名,則默認(rèn)是 modelValue
	modelValue:{ 
		type:String,
		default: 'test'
	},
	test2: {
		type: String,
		default: 'aaa'
	}
})

let message = ref('123')
let message2 = ref('456')
// 因?yàn)閜rops.modelValue、props.test2是非引用類(lèi)型,改變時(shí),需要監(jiān)聽(tīng),對(duì)響應(yīng)式數(shù)據(jù)重新賦值
watch(()=> props.modelValue,() => {message.value = props.modelValue})
watch(()=> props.test2,() => {message2.value = props.test2})
// 數(shù)據(jù)雙向綁定
const changeInfo = (info) => {
	emit('update:modelValue', info)
}
const changeInfo2 = (info2) => {
	emit('update:test2', info2)
}
</script>

子(常規(guī)寫(xiě)法)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-457573.html

<script>
import { ref, watch } from 'vue';
export default {
	props: {
		// 父組件 v-model 沒(méi)有指定參數(shù)名,則默認(rèn)是 modelValue
		modelValue:{
			type:String,
			default: 'test'
		},
		test2: {
			type: String,
			default: 'aaa'
		}
	},
	setup(props, { emit }) {
		let message = ref('123')
		let message2 = ref('456')
		// 因?yàn)閜rops.modelValue、props.test2是非引用類(lèi)型,改變時(shí),需要監(jiān)聽(tīng),對(duì)響應(yīng)式數(shù)據(jù)重新賦值
		watch(()=> props.modelValue,() => {message.value = props.modelValue})
		watch(()=> props.test2,() => {message2.value = props.test2})
		// 數(shù)據(jù)雙向綁定
		const changeInfo = (info) => {
			emit('update:modelValue', info)
		}
		const changeInfo2 = (info2) => {
			emit('update:test2', info2)
		}
		return {
			message, message2, changeInfo, changeInfo2
		}
	}
}
</script>

到了這里,關(guān)于vue3中emit(‘update:modelValue‘)使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 組件v-model(.sync)記錄使用(vue3)

    組件v-model(.sync)記錄使用(vue3)

    首先,讓我們來(lái)了解一下Vue3中v-model的用法。在Vue3中, v-model 指令可以用于自定義組件上,用于實(shí)現(xiàn)組件的雙向數(shù)據(jù)綁定。與Vue2中的 .sync 不同, Vue3中的v-model需要在組件中手動(dòng)實(shí)現(xiàn)雙向綁定邏輯。 下面是一個(gè)簡(jiǎn)單的父組件示例,展示了如何在Vue3中使用 v-model 來(lái)實(shí)現(xiàn)組件的雙

    2024年01月19日
    瀏覽(26)
  • Vue3-在HTML標(biāo)簽、組件標(biāo)簽上使用v-model

    本篇為Vue3學(xué)習(xí)中遇到的v-model相關(guān)的記錄,如有問(wèn)題歡迎指正 v-model通常在input、select等標(biāo)簽上來(lái)實(shí)現(xiàn)數(shù)據(jù)雙向綁定 原理 :v-model通過(guò)給標(biāo)簽value賦值來(lái)實(shí)現(xiàn)? 數(shù)據(jù)—頁(yè)面 的綁定。然后通過(guò)綁定input事件實(shí)現(xiàn) 頁(yè)面—數(shù)據(jù) 的綁定。 原理 :在組件上時(shí),v-model通過(guò) :modelValue 來(lái)進(jìn)行

    2024年01月24日
    瀏覽(25)
  • 【Vue技巧】Vue2和Vue3組件上使用v-model的實(shí)現(xiàn)原理

    ChatGPT4.0國(guó)內(nèi)站點(diǎn),支持GPT4 Vision 視覺(jué)模型:海鯨AI 在Vue中, v-model 是一個(gè)語(yǔ)法糖,用于在輸入框、選擇框等表單元素上創(chuàng)建雙向數(shù)據(jù)綁定。當(dāng)你在自定義組件中實(shí)現(xiàn) v-model 功能時(shí),你需要理解它背后的原理: v-model 實(shí)際上是一個(gè)屬性和一個(gè)事件的簡(jiǎn)寫(xiě)。 在 Vue 2.x 中, v-mode

    2024年01月15日
    瀏覽(29)
  • vue項(xiàng)目中對(duì)組件使用v-model綁定值,在vue3中如何更新數(shù)據(jù)

    vue項(xiàng)目中對(duì)組件使用v-model綁定值,在vue3中如何更新數(shù)據(jù)

    在el-form 中 el-form-item 綁定組件進(jìn)行校驗(yàn) 想在表單下面爆紅提示 可以對(duì)組件使用v-model綁定值 vue2 通過(guò)this.$emit(‘input’,value) 更新 v-model值 vue3 通過(guò)this.$emit(‘update:modelValue’ ,value) 更新 v-model值

    2024年02月15日
    瀏覽(20)
  • 面試官:只知道v-model是:modelValue和@onUpdate語(yǔ)法糖,那你可以走了

    面試官:只知道v-model是:modelValue和@onUpdate語(yǔ)法糖,那你可以走了

    我們每天都在用 v-model ,并且大家都知道在vue3中 v-model 是 :modelValue 和 @update:modelValue 的語(yǔ)法糖。那你知道 v-model 指令是如何變成組件上的 modelValue 屬性和 @update:modelValue 事件呢?將 v-model 指令轉(zhuǎn)換為 modelValue 屬性和 @update:modelValue 事件這一過(guò)程是在編譯時(shí)還是運(yùn)行時(shí)進(jìn)行的呢

    2024年03月26日
    瀏覽(26)
  • Vue3中v-model在原生元素和自定義組件上的使用

    Vue3中v-model在原生元素和自定義組件上的使用

    目錄 前言 一、原生元素上的用法 1.?輸入框(input) 2.?多行文本域(textarea) 3.?單選按鈕(radio) 4.?多選框(checkbox)? 5.?下拉選擇框(select)? 二、自定義組件上的用法 1.?定義一個(gè)名為 modelValue 的 props 屬性和一個(gè)名為 update:modelValue 的事件 2.使用一個(gè)可寫(xiě)的,同時(shí)具有 getter 和 setter

    2024年02月14日
    瀏覽(49)
  • 【vue3】vue3接收props以及emit的用法

    技術(shù) :vue3.2.40 UI框架 :arco-design 2.44.7 css技術(shù) :less 4.1.3 實(shí)現(xiàn) :子組件接收props以及通過(guò)emit方法傳值父組件 vue3使用的組合式API,我這里使用的是defineComponent 1.setup里如果需要接收props和使用emit,只需要帶參數(shù) setup(props, { emit }) 2.setup里面只需要帶emit(‘handleCancel’),不需要帶

    2024年02月15日
    瀏覽(24)
  • 父組件明明使用了v-model,子組件竟然可以不用定義props和emit拋出事件,快來(lái)看看吧

    父組件明明使用了v-model,子組件竟然可以不用定義props和emit拋出事件,快來(lái)看看吧

    vue3.4增加了 defineModel 宏函數(shù),在子組件內(nèi)修改了 defineModel 的返回值,父組件上 v-model 綁定的變量就會(huì)被更新。大家都知道 v-model 是 :modelValue 和 @update:modelValue 的語(yǔ)法糖,但是你知道為什么我們?cè)谧咏M件內(nèi)沒(méi)有寫(xiě)任何關(guān)于 props 的定義和 emit 事件觸發(fā)的代碼嗎?還有在 template

    2024年04月08日
    瀏覽(25)
  • 【vue3 之 emits & $emit() 講解 】監(jiān)聽(tīng)子組件事件、emit事件驗(yàn)證、options寫(xiě)法、composition setup寫(xiě)法

    前言:不懂在父組件里對(duì)子組件 @xxxx 聲明自定義事件,就不用看本篇文章了。本篇對(duì)此內(nèi)容不做任何說(shuō)明。這是與 emits 結(jié)合使用的必備知識(shí)! 場(chǎng)景說(shuō)明: 組件功能封裝: ????????組件封裝了一系列 emit?事件,并返回?cái)?shù)據(jù)、回調(diào)函數(shù)等,或單純執(zhí)行某個(gè)操作后,觸發(fā)父組

    2023年04月09日
    瀏覽(21)
  • vue3使用響應(yīng)式數(shù)據(jù) + v-model導(dǎo)致響應(yīng)式失效el-form表單無(wú)法輸入的問(wèn)題

    參考文章 重構(gòu)vue2項(xiàng)目時(shí)發(fā)現(xiàn)的問(wèn)題,原始項(xiàng)目使用的是 Element-ui 。 其實(shí)vue3可以使用適配的 Element-plus 問(wèn)題描述 el-form表單無(wú)法輸入 控制臺(tái)報(bào)錯(cuò) Avoid adding reactive properties to a Vue instance or its root $data at runtime - declare it upfront in the data option. 使用響應(yīng)式變量時(shí)應(yīng)先聲明 解決辦法

    2024年02月15日
    瀏覽(21)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包