在pages.json里面配置,使用subNVues
1 { 2 "path": "pages/appointmentRecovery/record/detail", 3 "style": { 4 "navigationBarTitleText": "預約詳情", 5 "app-plus": { 6 "subNVues": [{ 7 "id": "recordInfo", // 唯一標識 8 "path": "/pages/appointmentRecovery/record/info", // 頁面路徑 9 // "type": "popup", //原生子窗口內置樣式,可取值:'popup',彈出層;"navigationBar",導航欄 10 "style": { 11 "position": "absolute", 12 "bottom": "100upx", 13 "width": "100%", 14 "height": "50%", 15 "mask": "rgba(0,0,0,0)", 16 "style": { 17 "popGesture": "none" // 組織側滑返回, none,close 18 } 19 } 20 },{ 21 "id": "recordMap", // 唯一標識 22 "path": "/pages/appointmentRecovery/record/map", // 頁面路徑 23 // "type": "popup", //原生子窗口內置樣式,可取值:'popup',彈出層;"navigationBar",導航欄 24 "style": { 25 "position": "absolute", 26 "top": "0upx", 27 "left": 0, 28 "width": "100%", 29 "height": "50%", 30 "mask": "rgba(0,0,0,0)", 31 "style": { 32 "popGesture": "none" // 組織側滑返回, none,close 33 } 34 } 35 }] 36 } 37 } 38 },
在父頁面
// 根據id獲取聲明好的子頁面 this.subNvueMap = uni.getSubNVueById('recordMap'); // 設置子頁面的大小 this.subNvueMap.setStyle({ height: '50%' }); // 向子頁面傳參數 uni.$emit('to-modal1', JSON.stringify(obj)); // 通知子頁面以什么形式顯示 this.subNvueMap.show('slide-in-bottom', time, () => { console.log('顯示subNvueMap'); }); // 顯示
子頁面
// 子頁面是以.nvue結尾的文件 // 在created聲明周期中接收父頁面的傳參 uni.$on('to-modal1', data => { console.log('父組件傳遞給子組件的值', this.formData); }); // 在beforeDestroy生命周期銷毀監聽 uni.$off('to-modal1');