uniapp 組件傳參


父組件

<v-sub @returnDate=returnDate :backGround=backGround></v-sub>

import vSub from "../../../components/v-sub.vue"
	export default {
		components:{
			vSub
		},
		data() {
			return {
				backGround:"#000"
			}
		},
		methods: {
			returnDate(e){
				console.log("接收到的值==>>"+e)
			}
		}
	}
<device ref="device" :stoId="storeId" v-show="active == 'device'">
		</device>
		<battery ref="battery" :stoId="storeId" v-show="active == 'battery'">
		</battery>
		
import device from './components/device.vue'
	import battery from './components/battery.vue'
	export default {
		components: {
			device,
			battery
		},
		data() {
			return {
				storeId: null, // 參數storeId
				active: 'device' // 切換tab
			}
		},

子組件

<template>
	<view class="content" :style="[{background:backGround}]">
		<button @tap="passValue">點擊傳值</button>
	</view>
</template>
 
<script>
	export default {
		props:{
			backGround:{
				type:String,
				default:"#fff"
			}
		},
		methods:{
			passValue(){
				this.$emit("returnDate","yoyoyo")
			}
		}
	}
</script>
 
<style>
	.content{
		width: 400upx;
		height: 400upx;
	}
</style>

子類接收父類的數據,就會用到props

file

file

file

子組件給父組件傳值
首先在子類組件定義事件

file

file

file

file

父組件:
file

子組件
file

file

子組件

file

父組件

file

file


若本號內容有做得不到位的地方(比如:涉及版權或其他問題),請及時聯系我們進行整改即可,會在第一時間進行處理。


請點贊!因為你們的贊同/鼓勵是我寫作的最大動力!

歡迎關注達達的簡書!

這是一個有質量,有態度的博客

博客


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM