DEV Community

Cover image for Modifying hook methods with optionMergeStrategies
Jhonatan Morais
Jhonatan Morais

Posted on

Modifying hook methods with optionMergeStrategies

Welcome to VueJs mastering the API, today we will talk about the optionMergeStrategies method.

It provides us a powerful way to create plugins to intercept and modify the default behavior of Vue hook life cycle.

None of the official documentationhelps me to learn how to use it, So after some research finally learn a path.

How to use optionMergeStrategies

  1. Create the file: src/plugins/customMethods.js

  2. Now to install the plugin add the code to your src/main.js:

  3. Once installed our customMethod will be available in any component

  4. The console with print the messages at following order:
    Life cycle console prints

The customMethod executes him code right before the default createdMethod code, so if you need to run something before the default hooks code just replace the line 8 to another hookMethod from customMethod.js or overwrite another hookMethod.

If I help you please consider helping me too. Leave comments, share it. Believe me, your feedback it's really important to me.


Top comments (0)