#subNvue

#pages.json配置

详解:https://uniapp.dcloud.io/collocation/pages?id=app-subnvuesstyle

  1. {
  2. "path": "pages/index/index",
  3. "style": {
  4. "navigationBarTitleText": "组件",
  5. "navigationBarBackgroundColor": "#007AFF",
  6. "navigationBarTextStyle": "white",
  7. "app-plus" : {
  8. "titleNView" : true,
  9. "scrollIndicator" : "none",
  10. "bounce" : "none",
  11. "pullToRefresh" : {
  12. "support" : false
  13. },
  14. "subNVues":[{
  15. "id": "homeNvue", //弹窗id唯一
  16. "path": "pages/index/al-home-subNvue", //弹窗路径
  17. "type": "popup",
  18. "style": {
  19. "position": "absolute",
  20. // "mask": "rgba(0,0,0,0)", //弹窗背景
  21. "left":"0px",
  22. "bottom":"0px",
  23. "width": "750px",
  24. "height":"225px",
  25. "margin":"auto",
  26. "zindex": "999"
  27. }
  28. }]
  29. }
  30. }
  31. }

#打开弹窗

  1. // #ifdef APP-PLUS
  2. const subNVue = uni.getSubNVueById('homeNvue');
  3. subNVue.setStyle({
  4. 'background': 'transparent'
  5. })
  6. subNVue.show('slide-in-bottom', 300, function(){
  7. uni.showToast({
  8. title: '弹窗已打开',
  9. duration: 2000,
  10. icon: 'none'
  11. });
  12. });
  13. // #endif

详解:https://uniapp.dcloud.io/api/window/subNVues?id=subnvueshow

#关闭弹窗

  1. data () {
  2. return {
  3. subNvue: uni.getCurrentSubNVue()
  4. }
  5. }
  6. this.subNvue.hide('slide-out-bottom',300);

详解:https://uniapp.dcloud.io/api/window/subNVues?id=subnvuehide

#设置样式

  1. subNVue.setStyle({
  2. 'background': 'transparent'
  3. })

详解:https://uniapp.dcloud.io/api/window/subNVues?id=subnvuesetstyle

#通讯

详解: https://ask.dcloud.net.cn/article/35948

#自定义弹窗

思路:新建nvue页面,封装一个弹窗组件,打开这个页面,把页面背景设置透明度。

  1. pages.json配置 ```javascript { “path”: “pages/index/al-global-popup”, “style”: { “navigationBarBackgroundColor”: “#007AFF”,
    1. "navigationBarTextStyle": "white",
    2. "background": "transparent", //把页面背景设置透明,默认是白色
    3. "animationType": "fade-in"
    } },

//或者 { “path” : “pages/ucenter/agent-task-dialog”, “style”: { “navigationBarBackgroundColor”: “#007AFF”, “navigationBarTextStyle”: “white”, “background”: “transparent”, “animationType”: “fade-in”, “backgroundColor”: “rgba(255,255,255,0)”, “app-plus”: { “titleNView”: false } } }

  1. 2.nvue页面要设置蒙层
  2. ```javascript
  3. <div class="popup"></div>
  4. .popup {
  5. position: fixed;
  6. left: 0;
  7. top: 0;
  8. right: 0;
  9. bottom: 0;
  10. background-color: rgba(0,0,0,.4);
  11. justify-content: center;
  12. align-items: center;
  13. }

3.打开弹窗

  1. uni.navigateTo({
  2. url: '/pages/index/al-global-popup'
  3. })

4.关闭弹窗

  1. uni.navigateBack();