v-bind:style directive does not work with conditional comparisons
P粉321676640
P粉321676640 2024-03-31 17:56:41
0
1
314

I can bind classes to elements in vue based on the following conditions:

:class="i18n.global.locale == 'ar' ? 'class1': 'class2'"

But when I try to use the same conditional binding style like this:

:style="[i18n.global.locale == 'ar' ? { 'background': 'blue;' }: { 'background': 'red' } ]"
None of

styles are applied to this element. Why doesn't the :style directive work?

Both directives apply to the container div that contains all other elements.

P粉321676640
P粉321676640

reply all(1)
P粉722409996

I did some research on your problem, so to solve it you can do the following:

  1. Check the style of the element in the browser dev tools, it may happen that the bound style in the css file is overridden, for example, if you have a link to the css file
  2. Here { 'Background': 'Blue;' } Tried removing the ";", for me it started working when I removed it.
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!