native - 监听组件根元素的原生事件, 主要是给自定义的组件添加原生事件

官网的解释:
你可能想在某个组件的根元素上监听一个原生事件。可以使用 v-on 的修饰符 .native 。
通俗来讲:就是在父组件中给自定义的子组件绑定一个原生的事件,不加’. native’事件是无法触 发的,如下图
在这里插入图片描述

<template>
	<view>
		<TestValue style="color:red" title="hahhaha" @click.native="clickChild"  />
	</view>
</template>
<script>
	import TestValue from '@/components/TestValue.vue'
	export default {
    
    
		components:{
    
    TestValue},
		data() {
    
    
			return {
    
    
				title: 'Hello'
			}
		},
		onLoad() {
    
    

		},
		methods: {
    
    
			clickChild(){
    
    
				uni.showToast({
    
    title:"这是个子组件的事件"})
			}
		}
	}
</script>

猜你喜欢

转载自blog.csdn.net/qq_42859450/article/details/129355049