簡體   English   中英

在VueJs模板中向屬性添加字符

[英]Add character to attribute in VueJs Templating

所以說我有一個class label-dog

假設我想在VueJs元素中聲明類。

<img :class="type" >

與動物類像

data: { type: dog }

如何將“ label-”部分添加到類中? 是否有此語法?

您可以這樣操作:

<img :class="'label-' + type" >

您還可以定義一個計算屬性來“構建”您的類:

computed: {
  fullClass() {
    return 'label-'+ this.type;
  }
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM