Skip to content

Instantly share code, notes, and snippets.

@lpj145
Created May 14, 2021 13:54
Show Gist options
  • Save lpj145/d9a03292fa4bc023626f5ec5c663d945 to your computer and use it in GitHub Desktop.
Save lpj145/d9a03292fa4bc023626f5ec5c663d945 to your computer and use it in GitHub Desktop.
Strong expansable form.
<script>
export default {
name: 'FormTest',
provide: {
// Try to imagine what you can do with this approach
// So much to think :)
register(input) {
this.inputs.push(input)
}
},
data: () => ({
inputs: []
}),
methods: {
saveForm({ target }) {
const data = new FormData(target)
data.forEach((value, key) => {
console.log(`Field: ${key}, value: ${value}`)
})
// axios.post('/bla', data) You can use direct on axios
}
}
}
</script>
<template>
<form @submit.prevent="saveForm">
<input type="text" name="name">
<input type="radio" name="gender" value="M">
<input type="radio" name="gender" value="F">
<select name="job" id="">
<option>Develop</option>
<option>Teach</option>
<option>Nerd</option>
</select>
<button type="submit">Send</button>
</form>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment