Answer the question
In order to leave comments, you need to log in
How to display the value of a condition with a string in vue?
<p :class="'ic' + true ? 'on' : 'off' + '.svg'">123</p>
class="on"
, without additional text.
Answer the question
In order to leave comments, you need to log in
Vue has nothing to do with it. Understand operator precedence .
Let's add parentheses to make it clearer what is executed in what order:
Well, of course, writing such expressions in a template is not cool at all. Move it to a computed property or method, like so:
('ic' + true) ? 'on' : ('off' + '.svg')
computed: {
className() {
return условие ? 'icon.svg' : 'icoff.svg';
},
...
<p :class="className">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question