From 68c1a3596d926d263875637b46c53e0467a5d4d2 Mon Sep 17 00:00:00 2001 From: ygj6 <7699524+ygj6@users.noreply.github.com> Date: Sun, 1 Aug 2021 13:54:50 +0800 Subject: [PATCH] fix(function): properties of function should not disappear. (#778) --- src/mixin.ts | 4 ++++ test/setup.spec.js | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/mixin.ts b/src/mixin.ts index cebf5f82..88e4b0c9 100644 --- a/src/mixin.ts +++ b/src/mixin.ts @@ -124,7 +124,11 @@ export function mixin(Vue: VueConstructor) { if (!isRef(bindingValue)) { if (!isReactive(bindingValue)) { if (isFunction(bindingValue)) { + const copy = bindingValue bindingValue = bindingValue.bind(vm) + Object.keys(copy).forEach(function (ele) { + bindingValue[ele] = copy[ele] + }) } else if (!isObject(bindingValue)) { bindingValue = ref(bindingValue) } else if (hasReactiveArrayChild(bindingValue)) { diff --git a/test/setup.spec.js b/test/setup.spec.js index 527bf89f..ae29ec77 100644 --- a/test/setup.spec.js +++ b/test/setup.spec.js @@ -1193,4 +1193,30 @@ describe('setup', () => { const vm = new Vue(Constructor).$mount() expect(vm.proxy).toBe(originalProxy) }) + + // test #687 + it('properties of function should not disappear', () => { + Vue.component('todo', { + template: '
', + props: ['testFn'], + setup(props) { + expect(props.testFn.a).toBe(2) + }, + }) + + const vm = new Vue({ + template: ` +
+ +
+ `, + setup() { + const testFn = () => { + console.log(1) + } + testFn.a = 2 + return { testFn } + }, + }).$mount() + }) })