我有一个表单,我需要从占位符以及其他类型的 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);
}
}
最佳答案
使用 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>
关于javascript - 如何从vue js中的html属性调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46501392/