I have a form and I need to call a method from a placeholder and also from other types of html attribute.
Is there anyways I can call a vue method? Here is what I am trying to do
<input type="text" class="form-control" v-model="user.userName"
placeholder=t("un") required> // want to call method t() from the placeholder
It seems this method cannot be called this way. Is there any other ways to achieve this?
And my method is
methods: {
t(key){
console.log(key)
var local='fr';
return this.trans(key,local);
}
}
In short, for vue js call method from parent component in child, assign ref to the component. The other way around – call from the child in the parent component, emit an event in child and listen to it in the parent component.
We can call a Vue. js method on page load by calling it in the beforeMount component hook. We can also make a method run on page load by calling it in the created hook. And we can do the same in the mounted hook.
The simplest way to get started with Vue is to grab the development version script for it and add it to the head tag of your HTML file. Then you can start Vue code inside the HTML file inside of script tags. And have the Vue code connect up with an existing element on your HTML page.
We can define methods on a Vue instance by passing an object to the methods property. Vue methods are similar to JavaScript functions and allow us to add interactivity to our Vue apps.
Use v-bind
(https://v2.vuejs.org/v2/api/#v-bind)
<input type="text" class="form-control" v-model="user.userName"
v-bind:placeholder="t('un')" required>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With