How to use two conditional statements in VueJS
P粉877719694
P粉877719694 2024-02-17 15:36:23
0
2
369

I'm creating a sidebar with a lot of functionality so I need to add two conditions to my :class but I don't know how to do it. This is what I did:

:class=" showSidebar ? 'open' : 'closed', showSidebarMini ? 'openmini' : 'closedmini'"

P粉877719694
P粉877719694

reply all(2)
P粉441076405

You can use object styles to do the following:

Example:

{
  'open': showSidebar,
  'closed': !showSidebar,
  'openmini': showSidebarMini,
  'closedmini': !showSidebarMini
}

In your case:

:class="{ 'open': showSidebar, 'closed': !showSidebar, 'openmini': showSidebarMini, 'closedmini': !showSidebarMini }"
P粉333395496

You can use class array:

:class="[(showSidebar ? 'open' : 'closed'), (showSidebarMini ? 'openmini' : 'closedmini')]"
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template