问题
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