将多个属性绑定到 Vuetify 中的文本字段标签

Moh*_*asi 3 html javascript web vue.js vuetify.js

我想将包含多个值的字符串绑定到 vuetify 中的文本字段。我编写了以下代码,但它为我提供了字符串形式的属性。

<div v-if="textField">
      <v-text-field
      :value="'Our client, {{this.name}}, is {{this.age}} years old.'"
      outline
      readonly
      >
</v-text-field>
</div>
Run Code Online (Sandbox Code Playgroud)

输出是:

Our client, {{this.name}}, is {{this.age}} years old.
Run Code Online (Sandbox Code Playgroud)

尽管我想获得约翰32 的this.namethis.age值,如下所示:

Our client, John, is 32 years old.
Run Code Online (Sandbox Code Playgroud)

最好的方法是什么?

Psi*_*dom 5

或者直接在模板中使用模板文字作为:

<v-text-field
  :value="`Our client, ${name}, is ${age} years old.`"
  outline
  readonly
  >
Run Code Online (Sandbox Code Playgroud)

另请注意,不能在 HTML 属性中使用 Mustaches。也就是说,{{}}不适用于属性。

  • 你在字符串周围使用反引号 ` 吗?请注意,它不是单引号。 (2认同)