S
S
stanislavkm2022-04-18 20:47:36
Vue.js
stanislavkm, 2022-04-18 20:47:36

How to properly send form data to vue?

There is a form. With inputs and button values ​​(to select delivery or pickup, to pay by card or cash, etc.). Linking inputs using v-model is understandable, but how to link to the value of the selected buttons?
Code snippet:

...
              <div>
                <input v-model="name" class="order_input" type="text" placeholder="Имя" >
              </div>
...
              <div v-if="cafeIsActive" class="select_type">
                <p class="radio_p">Выберите кафе</p>
                <div class="radio_btns">
                  <div class="form_radio_btn">
                    <input id="radio-5" type="radio" name="cafeID" value="cafe1" checked>
                    <label for="radio-5">Кафе 1</label>
                  </div>
                  <div  class="form_radio_btn" >
                    <input id="radio-6" type="radio" name="cafeID" value="cafe2">
                    <label for="radio-6">Кафе 2</label>
                  </div>
                </div>
              </div>


Then I hang an event on the send data button, in which I describe the function of sending data using post axios-a. And how to choose which values ​​to send in the request? If possible it would be ideal to see an example

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2022-04-18
@Kostik_1993

axios.post(url, this.$data)

axios.post(url, {
  name: this.name,
  foo: this.foo,
  bar: this.bar
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question