0

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.

3
  • github.com/yogeshgalav/vue-form-mixin Commented Feb 27, 2022 at 12:01
  • Should it be like declaring and alternative variable to $ref['mycomponent']. Please help me with concept. Commented Feb 27, 2022 at 12:02
  • Also can I use document.getElementsByName() inside component? Commented Feb 27, 2022 at 12:09

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I can't use it everywhere, Can I define $validate inside component?
If not work in component, you can assign it to a component property on "component create" , but I think if you define it globally in main file, it will work in template as well.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.