Home > database >  How to use variable from component to be published in vue?
How to use variable from component to be published in vue?

Time:02-28

I am creating a validation component to be published. Just like vee-validate I want to use a variable this.$validate.bla() ? where bla is function in my component.

CodePudding user response:

in your main file:

import Validate from 'your_validation_module';
Object.defineProperty(Vue.prototype, '$Validate', {
    value: Validate
});

then use like this in your code :

this.$Validate.blah()

in Vue3 you should use Provide/Inject , app level provide

  • Related