Skip to content

Commit e54984f

Browse files
committed
fix: 修复事件函数中的this指向问题
1 parent d51fe03 commit e54984f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

packages/vue2/src/init.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ const init = (appConfig, platformConfig, routes, metaData) => {
7272
for (let index = 0; index < endEventLists.length; index++) {
7373
const name = endEventLists[index];
7474
if (metaData && name && metaData.frontendEvents[name]) {
75-
// 确保事件函数中的this指向Vue.prototype
75+
// 事件函数中的this指向Vue.prototype
7676
unsafeEval.bind(Vue.prototype)(metaData.frontendEvents[name]);
7777
Vue.prototype[name] = window[name];
78+
} else if (window[name] && typeof window[name] === 'function') {
79+
// 事件函数中的this指向Vue.prototype
80+
window[name] = window[name].bind(Vue.prototype);
81+
Vue.prototype[name] = window[name];
7882
}
7983
}
8084
}

0 commit comments

Comments
 (0)