小程序全局弹窗

目前我们的小程序有个需求,就是在小程序内部收到消息时,希望能弹出一个通知框提醒用户。不管是安卓还是苹果设备,我们都希望能实现这个功能,而且是系统自动弹出通知框的方式。

难点在于需要全局。

参考以后思路:注册全局app.js,这个可以试试

参考:小程序全局弹窗如何实现啊? | 微信开放社区

https://www.cnblogs.com/LindaBlog/p/16636134.html

微信小程序的全局弹窗以及全局实例

最后实现:

1.全局引入组件()
main.js内:
import privacyCheck from '@/public/colorui/components/privacyCheck.js'
import auditingNotice from '@/public/colorui/components/auditing-notice.vue'

Vue.component('auditingNotice', auditingNotice)
Vue.prototype.$privacyCheck=privacyCheck

2.如何在界面上插入组件
 chainWebpack: config => {
        if(process.env.UNI_PLATFORM !=='app-plus' && process.env.UNI_PLATFORM !== 'h5'){
            config.module.rule('vue').use('vue-loader').loader('vue-loader').tap(options => {
                const compile = options.compiler.compile
                options.compiler.compile = (template, ...args) => {
                    if (args[0].resourcePath.match(/^pages/)) {
                        template = template.replace(/[\s\S]+?<[\d\D]+?>/, _ => `${_}<messageNotice ref="privacyDialog" />`)
                    }else if(args[0].resourcePath.match(/^others/)){
                        if(args[0].resourcePath.indexOf('others/components') == -1 && args[0].resourcePath.indexOf('others/@lucky-canvas') == -1 && args[0].resourcePath.indexOf('others/message/chat') == -1){
                            template = template.replace(/[\s\S]+?<[\d\D]+?>/, _ => `${_}<messageNotice ref="privacyDialog" />`)
                        }
                    }else if(args[0].resourcePath.match(/^sub1/)){
                        if(args[0].resourcePath.indexOf('sub1/components' == -1)){
                            template = template.replace(/[\s\S]+?<[\d\D]+?>/, _ => `${_}<messageNotice ref="privacyDialog" />`)
                        }
                    };
                    return compile(template, ...args)
                }
                return options
            })
        }
    }

3.如何调用全局组件
that.$privacyCheck({
        result
    })

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值