N
N
Nikolay Semenov2017-08-28 08:36:42
JavaScript
Nikolay Semenov, 2017-08-28 08:36:42

How to assign class depending on props value in vue?

Hello!
Tell me how to add a specific class depending on the props value, i.e.
there is a child component

<template lang="pug">
  ul.gender
    li
      div(id="male" @click="value = 'Мужчина'" :class="[value='Мужчина' ? 'active' : false]") 
      span {{ value }}
    li
      div(id="female" @click="value = 'Женщина'" :class="[value='Женщина' ? 'active' : false]")
      span Женщина
</template>

<script>
export default {
  props: ['value'],
}
</script>

<style lang="scss">
  .gender {
    margin: 0;
    padding: 0;
    list-style-type: none;
    background: #ffffff;
    color: #ccc;
    li {
      display: flex;
    }
  }
  #male, #female {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .2)
  } 
</style>

the value value comes to it, the
task is such that if the value value is equal to the value of the string (selection), then this string needs to be given a specific class,
I tried to set the class, but nonsense comes out

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question