vuejs / vue-class-component

ES / TypeScript decorator for class-style Vue components.
MIT License
5.81k stars 431 forks source link

call custom function after calling originalMethod.apply in custom decorator #622

Closed mohammad-zr closed 1 year ago

mohammad-zr commented 1 year ago

How to call a function after calling originalMethod.apply(this, args) in a custom decorator?

import { createDecorator } from 'vue-class-component'

export const Log = createDecorator((options, key) => {
  const originalMethod = options.methods[key]

  options.methods[key] = function wrapperMethod(...args) {
    console.log('BEFORE')
    originalMethod.apply(this, args)
    console.log('AFTER') // I want this but not called
  }
})