G
G
gitdev2017-12-28 13:09:03
Windows
gitdev, 2017-12-28 13:09:03

How to implement the frontend part of submitting a form in Vue.js?

Is there a good example of submitting a form (binding form data and sending a post request with the data to the server)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sasha Ketch, 2019-10-20
@sashaKetch

Throw the most important files on a USB flash drive, olako, etc. Format your hard drive or SSD and reinstall Windows.
And when it lags again, do the same thing.

A
Askhat Bikmetov, 2017-12-28
@gitdev

<template>
  <form>
    <p v-if='errorMessage'>{{ errorMessage }}</p>
    <input type='text' v-model='username'/>
    <input type='password' v-model='password'/>
    <button @click='send()'>Log in</button>
  </form>
</template>

<script>
import someHttpClient from 'someHttpClient'

export default {
  data: {
    return {
      username: '',
      password: '',
      errorMessage: ''
    }
  },
  methods: {
    send () {
      var username, password, errorMessage = this
      if (username && password) {
        errorMessage = ''
        someHttpClient.sendAndMaybeCipher({ username, password })
      } else {
        errorMessage = 'Form not filled properly'
      }
    }
  }
}
</script>

Request examples:
  • What is the difference between a post ajax request and a get request?
  • What value from input type=file to pass to the server?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question