提交 9175cb77 编写于 作者: fxy060608's avatar fxy060608

feat(v3): getApp({allowDefault:true})

上级 61f8e378
......@@ -11538,9 +11538,20 @@ var serviceContext = (function () {
let appCtx;
function getApp$1 () {
const defaultApp = {
globalData: {}
};
function getApp$1 ({
allowDefault = false
} = {}) {
if (appCtx) { // 真实的 App 已初始化
return appCtx
}
if (allowDefault) { // 返回默认实现
return defaultApp
}
}
function initGlobalListeners () {
const emit = UniServiceJSBridge.emit;
......@@ -11635,7 +11646,11 @@ var serviceContext = (function () {
appCtx = appVm;
appCtx.globalData = appVm.$options.globalData || {};
Object.assign(appCtx, defaultApp); // 拷贝默认实现
const globalData = appVm.$options.globalData || {};
// merge globalData
appCtx.globalData = Object.assign(globalData, appCtx.globalData);
initOn(UniServiceJSBridge.on, {
getApp: getApp$1,
......
......@@ -36,8 +36,19 @@ import {
let appCtx
export function getApp () {
const defaultApp = {
globalData: {}
}
export function getApp ({
allowDefault = false
} = {}) {
if (appCtx) { // 真实的 App 已初始化
return appCtx
}
if (allowDefault) { // 返回默认实现
return defaultApp
}
}
function initGlobalListeners () {
......@@ -133,7 +144,11 @@ export function registerApp (appVm) {
appCtx = appVm
appCtx.globalData = appVm.$options.globalData || {}
Object.assign(appCtx, defaultApp) // 拷贝默认实现
const globalData = appVm.$options.globalData || {}
// merge globalData
appCtx.globalData = Object.assign(globalData, appCtx.globalData)
initOn(UniServiceJSBridge.on, {
getApp,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册