最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

uni-app實現(xiàn)頁面通信EventChannel的操作方法

 更新時間:2024年05月31日 10:58:04   作者:幸福了,然后呢  
使用了EventBus的方法實現(xiàn)不同頁面組件之間的一個通信,在uni-app中,我們也可以使用uni-app API,uni.navigateTo來實現(xiàn)頁面間的通信,這篇文章主要介紹了uni-app實現(xiàn)頁面通信EventChannel的操作方法,需要的朋友可以參考下

uni-app實現(xiàn)頁面通信EventChannel

之前使用了EventBus的方法實現(xiàn)不同頁面組件之間的一個通信,在uni-app中,我們也可以使用uni-app API —— uni.navigateTo來實現(xiàn)頁面間的通信。注:2.8.9+ 支持頁面間事件通信通道。

1. 向被打開頁面?zhèn)魉蛿?shù)據(jù)

// index.vue
<script setup>
	uni.navigateTo({
		url: '/pages/tender/detail', // 跳轉詳情頁面
	    success:function(res){
	      // 通過eventChannel向被打開頁面?zhèn)魉蛿?shù)據(jù)
	      res.eventChannel.emit('toDetailEmits', { data: 'index to detail' })
	    }
	});
</script>
// detail.vue
import { onLoad } from '@dcloudio/uni-app';
import { ref, getCurrentInstance} from 'vue';
const instance = getCurrentInstance().proxy
<script setup>
	onLoad(()=>{
		const eventChannel = instance.getOpenerEventChannel();
		eventChannel.on('toDetailEmits',(data)=>{
		  console.log(data,'data') // 輸出結果如下
		})
	})
</script>

2. 如果需要獲取被打開頁面?zhèn)魉偷疆斍绊撁娴臄?shù)據(jù)

// index.vue
<script setup>
	uni.navigateTo({
		url: '/pages/tender/detail', // 跳轉詳情頁面
	    events:{
	      // 為指定事件添加一個監(jiān)聽器,獲取被打開頁面?zhèn)魉偷疆斍绊撁娴臄?shù)據(jù)
	      updataEmits:function(data){
	        console.log(data,'data index')  // 輸出結果如下
	        // 可以在當前頁做一些操作....
	      }
	    },
	    success:function(res){
	      // 通過eventChannel向被打開頁面?zhèn)魉蛿?shù)據(jù)
	      res.eventChannel.emit('toDetailEmits', { data: 'index to detail' })
	    }
	});
</script>
// detail.vue
import { onLoad } from '@dcloudio/uni-app';
import { ref, getCurrentInstance} from 'vue';
const instance = getCurrentInstance().proxy
<script setup>
	// 如點擊某一按鈕
	const cancle = () => {
		const eventChannel = instance.getOpenerEventChannel();
	    eventChannel.emit('updataEmits',{data:'detail to index'})
	    uni.navigateBack()
	}
	onLoad(()=>{
		const eventChannel = instance.getOpenerEventChannel();
		eventChannel.on('toDetailEmits',(data)=>{
		  console.log(data,'data') 
		})
	})
</script>

到此這篇關于uni-app實現(xiàn)頁面通信EventChannel的操作方法的文章就介紹到這了,更多相關uni-app頁面通信EventChannel內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

丰镇市| 昭通市| 汉川市| 泸州市| 中方县| 义乌市| 丽江市| 克山县| 屯昌县| 长治市| 远安县| 保德县| 台山市| 昭苏县| 邳州市| 富源县| 盐山县| 昌乐县| 廉江市| 达孜县| 汤原县| 新泰市| 屯昌县| 北海市| 贡觉县| 英吉沙县| 六枝特区| 舟曲县| 桃园市| 克什克腾旗| 专栏| 武穴市| 昆明市| 康乐县| 略阳县| 秀山| 甘谷县| 浪卡子县| 玉溪市| 保靖县| 平远县|