5

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);
      }
}
6
  • 1
    What do you mean by calling a method from placeholder? Maybe you want computed properties? Commented Sep 30, 2017 at 9:20
  • Hi, thank you for the response. It is not an event. I am trying to call a method t() which is declared inside my methods from the placeholder attribute Commented Sep 30, 2017 at 9:23
  • I have edited the question. Commented Sep 30, 2017 at 9:25
  • Do you want to translate your placeholder? Commented Sep 30, 2017 at 9:30
  • yes and translation logic is defined in the t() method. Commented Sep 30, 2017 at 9:30

2 Answers 2

10

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Great, I tried everything except '' single quotation :)
@sadek ah, yes. You cannot nest " inside " without escaping them. The alternative is to use the '.
1
<input type="text" class="form-control" v-model="user.userName" :placeholder="t('un')" required>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.