日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

uni-app 組件與頁面事件傳值 this.$emit

作者:maoge_666 更新時間: 2023-07-15 編程語言

1、組件內頁面 test.vue

<template>
    <view>
    	<text>我是test組件{{title}}</text>
        <button type="primary" @click="test">按鈕傳值回調</button>
    </view>
</template>

<script>
    export default {
        data() {
            return {     
               myname:'哈哈'           
            };
        },
        props:{
        title:''
        },
        methods:{
            test(){
                console.log("組件中的按鈕點擊事件")
                //觸發子視圖中的該事件方法
                //定義一個事件名,在子頁面中觸發該方法名
                this.$emit("testShowName",this.myname)
            }         
        }
    }
</script>

2、子頁面

<template>
	<view>
		//組件使用
		<test :title="title" @testShowName="testEvent"></test>
	</view>
</template>

<script>
	import test from "@/components/test/test.vue" //引入組建
	export default {
		data() {
			return {
				title:'lele'
			};
		},
		onLoad() {
			
		},
		components: {
			test 
		},
		methods: {
			testEvent(e) {
				console.log("當前事件的值就是:",e)
			}
		}
	}
</script>

原文鏈接:https://blog.csdn.net/maoge_666/article/details/131663198

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新