目前我们的小程序有个需求,就是在小程序内部收到消息时,希望能弹出一个通知框提醒用户。不管是安卓还是苹果设备,我们都希望能实现这个功能,而且是系统自动弹出通知框的方式。
难点在于需要全局。
参考以后思路:注册全局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
})