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

uniapp框架組件、props對(duì)組件傳值、對(duì)組件綁定事件的使用、子組件給父組件傳值

這篇具有很好參考價(jià)值的文章主要介紹了uniapp框架組件、props對(duì)組件傳值、對(duì)組件綁定事件的使用、子組件給父組件傳值。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

新建組件的方式,在components目錄下新建組件,然后就能在pages頁(yè)面當(dāng)中直接使用該組件
uniapp props使用,微信小程序,微信小程序

test.vue

<template>
	<view>
		test
	</view>
</template>

<script>
	export default {
		name:"test",
		data() {
			return {
				
			};
		}
	}
</script>

<style lang="scss">

</style>

home.vue:

<template>
	<view>
		<uni-icons type="search" size="17"></uni-icons>
		<test></test>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				
			};
		},
		methods:{
			
		}
	}
</script>

<style lang="scss">

</style>

頁(yè)面效果如下:
uniapp props使用,微信小程序,微信小程序

props的作用就是可以從外部的標(biāo)簽當(dāng)中傳值到標(biāo)簽當(dāng)中的內(nèi)容

props的使用方法:在子組件當(dāng)中,props是一個(gè)對(duì)象,對(duì)象當(dāng)中的數(shù)據(jù)也是一個(gè)對(duì)象,該有兩個(gè)屬性,type是數(shù)據(jù)的類型,default是數(shù)據(jù)的默認(rèn)值,當(dāng)父組件沒有傳值時(shí)使用默認(rèn)值。在vue.js當(dāng)中props是一個(gè)數(shù)組,并且里面的數(shù)據(jù)是字符串類型

在test.vue組件當(dāng)中

<template>
	<view :style="{'color':yanse}">
		{{msg}}
	</view>
</template>

<script>
	export default {
		props:{
			yanse:{
				type:String,
				default:'red'
			}
		},
		name:"test",
		data() {
			return {
				msg:'test'
			};
		},
		
	}
</script>

<style lang="scss">

</style>

在home.vue頁(yè)面當(dāng)中

<template>
	<view>
		<uni-icons type="search" size="17"></uni-icons>
		<test :yanse="'yellow'"></test>
		{{msg}}
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				msg:'hello'
			};
		},
		methods:{
			
		}
	}
</script>

<style lang="scss">

</style>

頁(yè)面效果:

uniapp props使用,微信小程序,微信小程序

在屬性的值前面加一個(gè):代表著引用變量的值

對(duì)組件綁定事件:

<template>
	<view :style="{'color':yanse}" @click="test">
		{{msg}}
	</view>
</template>

<script>
	export default {
		props:{
			yanse:{
				type:String,
				default:'red'
			}
		},
		name:"test",
		data() {
			return {
				msg:'test'
			};
		},
		methods:{
			test:function(){
				console.log('test');
			}
		}
	}
</script>

<style lang="scss">

</style>

動(dòng)態(tài)設(shè)置style屬性:

<view class="nr" v-for="(item,index) in classification" :key="index" :style="'color:'+item.color">

子組件傳父組件:主要通過this.$emit(event,message)
$emit 綁定一個(gè)自定義事件event,當(dāng)這個(gè)這個(gè)語句被執(zhí)行到的時(shí)候,就會(huì)將參數(shù)message傳遞給父組件,父組件通過@event監(jiān)聽并接收參數(shù)。

子組件:

<view v-for="(item,index) in fenlei" :key='index' v-on:click="dianji(index)">
			<view class="text" :style="'color:'+item.color">
				{{item.text}}
			</view>
		</view>
dianji:function(e){
	var that = this;
	
	console.log(e);
	this.$emit('fenleiEvent',e);
	
}

父組件:文章來源地址http://www.zghlxwxcb.cn/news/detail-606023.html

<fenlei @fenleiEvent='show'></fenlei>

show(e){
	console.log('父組件接收:')
		console.log(e);
	}

到了這里,關(guān)于uniapp框架組件、props對(duì)組件傳值、對(duì)組件綁定事件的使用、子組件給父組件傳值的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(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)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包