Skip to content

Commit 68c1a35

Browse files
authored
fix(function): properties of function should not disappear. (#778)
1 parent 6890852 commit 68c1a35

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/mixin.ts

+4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ export function mixin(Vue: VueConstructor) {
124124
if (!isRef(bindingValue)) {
125125
if (!isReactive(bindingValue)) {
126126
if (isFunction(bindingValue)) {
127+
const copy = bindingValue
127128
bindingValue = bindingValue.bind(vm)
129+
Object.keys(copy).forEach(function (ele) {
130+
bindingValue[ele] = copy[ele]
131+
})
128132
} else if (!isObject(bindingValue)) {
129133
bindingValue = ref(bindingValue)
130134
} else if (hasReactiveArrayChild(bindingValue)) {

test/setup.spec.js

+26
Original file line numberDiff line numberDiff line change
@@ -1193,4 +1193,30 @@ describe('setup', () => {
11931193
const vm = new Vue(Constructor).$mount()
11941194
expect(vm.proxy).toBe(originalProxy)
11951195
})
1196+
1197+
// test #687
1198+
it('properties of function should not disappear', () => {
1199+
Vue.component('todo', {
1200+
template: '<div/>',
1201+
props: ['testFn'],
1202+
setup(props) {
1203+
expect(props.testFn.a).toBe(2)
1204+
},
1205+
})
1206+
1207+
const vm = new Vue({
1208+
template: `
1209+
<div>
1210+
<todo :testFn="testFn"></todo>
1211+
</div>
1212+
`,
1213+
setup() {
1214+
const testFn = () => {
1215+
console.log(1)
1216+
}
1217+
testFn.a = 2
1218+
return { testFn }
1219+
},
1220+
}).$mount()
1221+
})
11961222
})

0 commit comments

Comments
 (0)