native - Listen to the native event of the root element of the component, mainly to add native events to the custom component

Explanation on the official website:
You may want to listen to a native event on the root element of a component. The v-on modifier .native can be used.
In layman's terms: it is to bind a native event to the custom child component in the parent component, and the event cannot be triggered without adding '. native', as shown in the figure below
insert image description here

<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>

Guess you like

Origin blog.csdn.net/qq_42859450/article/details/129355049
Recommended