简体   繁体   English

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

[英]Add character to attribute in VueJs Templating

So let say I have a class label-dog . 所以说我有一个class label-dog

Let say I want to declare the class in a VueJs element like. 假设我想在VueJs元素中声明类。

<img :class="type" >

With class of animal being something like 与动物类像

data: { type: dog }

How do I add the "label-" part to the class? 如何将“ label-”部分添加到类中? Is there a syntax for this? 是否有此语法?

You can do it this way: 您可以这样操作:

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

You can also define a computed property to 'build' your class: 您还可以定义一个计算属性来“构建”您的类:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM