How can I combine class with class that has condition? vue.js 2

泪湿孤枕 提交于 2020-01-17 06:38:07

问题


My vue component is like this :

<template>
    <a class="btn btn-block" :class="[response == 'responseFound' ? ' btn-yellow' : ' btn-default']">
    ...
    </a>
 </template>

It works

But, I want to combine it to be one class

I try like this :

<template>
    <a :class="'btn' [response == 'responseFound' ? ' btn-yellow' : ' btn-default'] ' btn-block'">
    ...
    </a>
 </template>

But it does not work

How can I solve it?


回答1:


Everything inside :class or v-bind:class is an expression. So:

<template>
    <a :class="'btn' + ( response == 'responseFound' ? ' btn-yellow' : ' btn-default') + ' btn-block'">
    ...
    </a>
 </template>


来源:https://stackoverflow.com/questions/43759229/how-can-i-combine-class-with-class-that-has-condition-vue-js-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!