From a653b7bfb2cdf2b7b413722f04035c2a941b4c6a Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 19 Nov 2019 17:39:44 +0800 Subject: [PATCH] feat(mp): getApp() add methods #665 --- .../runtime/wrapper/app-base-parser.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/platforms/mp-weixin/runtime/wrapper/app-base-parser.js b/src/platforms/mp-weixin/runtime/wrapper/app-base-parser.js index 2a05720f1..f0fea7f28 100644 --- a/src/platforms/mp-weixin/runtime/wrapper/app-base-parser.js +++ b/src/platforms/mp-weixin/runtime/wrapper/app-base-parser.js @@ -15,10 +15,10 @@ const hooks = [ export default function parseBaseApp (vm, { mocks, initRefs -}) { - if (vm.$options.store) { - Vue.prototype.$store = vm.$options.store - } +}) { + if (vm.$options.store) { + Vue.prototype.$store = vm.$options.store + } Vue.prototype.mpHost = __PLATFORM__ @@ -64,8 +64,8 @@ export default function parseBaseApp (vm, { app: this } - this.$vm.$scope = this - // vm 上也挂载 globalData + this.$vm.$scope = this + // vm 上也挂载 globalData this.$vm.globalData = this.globalData this.$vm._isMounted = true @@ -77,6 +77,13 @@ export default function parseBaseApp (vm, { // 兼容旧版本 globalData appOptions.globalData = vm.$options.globalData || {} + // 将 methods 中的方法挂在 getApp() 中 + const methods = vm.$options.methods + if (methods) { + Object.keys(methods).forEach(name => { + appOptions[name] = methods[name] + }) + } initHooks(appOptions, hooks) -- GitLab