vue开发组件开发中的小技巧

声明:以下随笔由博主自主编写,也有部分引用网友的,引用部分版权归原作者所有,其他博主原创部分禁止转载、复制全部或部分用以重新发布!


vue递归组件事件阻止冒泡

其实这里主要还有递归组件的自定义事件不生效等一系列问题

<template>
	<view class="body">
		<view v-for="(item,index) in data" :key="item.id">
			<template v-if="!item.children.length">
				<view class="item" @click.stop="select(item)">
				</view>
			</template>
			<template v-else>
				<!-- 这里是关键的  v-on="$listeners"-->
					<!-- 由网友分享:https://blog.csdn.net/weixin_43120290/article/details/125068448 -->
				<xf-tree :data="item.children" v-on="$listeners"></xf-tree>
			</template>
		</view>
	</view>
</template>
<script>
methods: {
	select(e) {
		// 在uniapp中,这里用this,用uni好像没得作用
		return this.$emit('click', e)
	}
},
</script>

JavaScript移除一个对象

// 转载于https://www.cnblogs.com/luyj00436/p/15076312.html
const obj = { a : 1, b : 2 }
delete obj.a
console.log(obj) //{ b : 2 }
posted @ 2022-07-21 23:45  小枫同学  阅读(27)  评论(0编辑  收藏  举报