A
A
Alianos2021-04-25 14:49:05
Vue.js
Alianos, 2021-04-25 14:49:05

How to find out which input type="radio" element is checked?

Hello, please tell me how can I find out which element from input type="radio" is checked. Are there native methods for this and not overkill. Does it make sense to store which checked element in a variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Levchenko, 2021-04-25
@Alianos

You are doing some kind of crap, judging by your description, why use radiobuttons to implement a dropdown list? You should read the documentation for Vue. But I will answer the question of how to find out which radio button is checked:

<template>
  <div class="example">
    <input type="radio" value="Один" v-model="radioValue">
    <label>Один</label>
    <br>
    <input type="radio" value="Два" v-model="radioValue">
    <label>Два</label>
    <br>
    Выбрано: {{ radioValue }}
    <br>
    <button @click="uncheckRadio">Сбросить значение</button>
  </div>
</template>
<script>
export default {
  name: 'example',
  data() {
    return {
      radioValue: '',
    };
  },
  methods: {
    uncheckRadio() {
      this.radioValue = '';
    },
  },
  watch: {
    radioValue(value) {
      console.log(value); // какая-то логика при изменении значения
    },
  },
};
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question