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() + }) })