vuejs form handing code example
Example 1: submit form in vue
//HTML
<div id="vueRoot">
<form ref="form">
<input name="vitalInformation" v-model="store.vital">
<a href="#" v-on:click="submit">SUBMIT</a>
</form>
</div>
//JS
vm = new Vue({
el : "#vueRoot",
methods : {
submit : function(){
this.$refs.form.submit()
}
}
});
Example 2: how manipulate the multiple input option data in one function in vue js
<template>
<select
:class="$options.name"
v-model="selected"
@change="updateValue"
>
<option
disabled
value=""
v-text="disabledOption"
/>
<option
v-for="option in options"
:key="option"
:value="option"
v-text="option"
/>
</select>
</template>
<script>
export default {
name: 'FormSelect',
model: {
event: 'change',
},
props: {
disabledOption: {
type: String,
default: 'Select something',
},
options: {
type: Array,
default: () => [],
},
value: {
type: [String, Number],
default: null,
},
},
data() {
return {
selected: this.value,
};
},
methods: {
updateValue() {
this.$emit('change', this.selected);
},
},
};
</script>
Example 3: vue form
<input v-model="message" placeholder="edit me">
<p>Message is: {{ message }}</p>