亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用@tap.stop阻止事件繼續(xù)傳播

 更新時(shí)間:2022年03月26日 16:15:18   作者:%程序羊%  
這篇文章主要介紹了使用@tap.stop阻止事件繼續(xù)傳播,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

@tap.stop阻止事件繼續(xù)傳播

在uni-app開發(fā)當(dāng)中,難免會(huì)遇到外層view嵌套內(nèi)層view,又同時(shí)都含有點(diǎn)擊事件,這樣就會(huì)起沖突。

為了防止事件的繼續(xù)傳播我們就會(huì)用到事件修飾符.stop 

先看代碼:

<template>
?? ?<view class="wai" @tap="waiTab">
?? ??? ?<h5>外面</h5>
?? ??? ?<view class="nei" @tap="neiTab">
?? ??? ??? ?<h5>內(nèi)部</h5>
?? ??? ?</view>
?? ?</view>
</template>
<script>
?? ?export default {
?? ??? ?data() {
?? ??? ??? ?return {
?? ??? ??? ??? ?
?? ??? ??? ?}
?? ??? ?},
?? ??? ?methods: {
?? ??? ??? ?waiTab(){
?? ??? ??? ??? ?console.log("點(diǎn)擊了外邊")
?? ??? ??? ?},
?? ??? ??? ?neiTab(){
?? ??? ??? ??? ?console.log("點(diǎn)擊了內(nèi)部")
?? ??? ??? ?}
?? ??? ?}
?? ?}
</script>
<style>
?? ?.wai{
?? ??? ?width: 100%;
?? ??? ?height: 100px;
?? ??? ?display: flex;
?? ??? ?justify-content: center;
?? ??? ?background-color: #0000FF;
?? ?}
?? ?.nei{
?? ??? ?display: flex;
?? ??? ?justify-content: center;
?? ??? ?align-items: center;
?? ??? ?width: 50px;
?? ??? ?height: 50px;
?? ??? ?background-color: #00CE47;
?? ?}
</style>

效果是這樣的:

當(dāng)我們點(diǎn)擊外部時(shí):

當(dāng)我們點(diǎn)擊內(nèi)部時(shí):

解決方法:只需在@tap后面加.stop就可以阻止事件繼續(xù)傳播

<view class="wai" @tap.stop="waiTab">
		<h5>外面</h5>
		<view class="nei" @tap.stop="neiTab">
			<h5>內(nèi)部</h5>
		</view>
	</view>

uniapp+uview @tap.stop="stop"組織冒泡失效bug

阻止事件冒泡時(shí),直接在需要使用的方法上加.stop無(wú)效

需要在外層加一層標(biāo)簽 <view @tap.stop=“stop”>

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論