如何在Vue JS中从HTML属性调用方法

卡德克(Had Sadek)

我有一个表单,我需要从占位符以及其他类型的html属性调用方法。

无论如何,我可以调用vue方法吗?这是我想做的

<input type="text" class="form-control" v-model="user.userName" 
 placeholder=t("un") required> // want to call method t() from the placeholder

似乎无法以这种方式调用此方法。还有其他方法可以做到这一点吗?

我的方法是

methods: {
   t(key){
        console.log(key)
        var local='fr';
        return this.trans(key,local);
      }
}
加布里埃莱·彼得里奥利(Gabriele Petrioli)

使用v-bindhttps://vuejs.org/v2/api/#v-bind

<input type="text" class="form-control" v-model="user.userName" 
 v-bind:placeholder="t('un')" required>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章