Skip to content

Commit

Permalink
fix(function): properties of function should not disappear. (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Aug 1, 2021
1 parent 6890852 commit 68c1a35
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/mixin.ts
Expand Up @@ -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)) {
Expand Down
26 changes: 26 additions & 0 deletions test/setup.spec.js
Expand Up @@ -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: '<div/>',
props: ['testFn'],
setup(props) {
expect(props.testFn.a).toBe(2)
},
})

const vm = new Vue({
template: `
<div>
<todo :testFn="testFn"></todo>
</div>
`,
setup() {
const testFn = () => {
console.log(1)
}
testFn.a = 2
return { testFn }
},
}).$mount()
})
})

0 comments on commit 68c1a35

Please sign in to comment.