vue does not click the submit button and triggers submit when input is typed. I don"t know why.
because I don"t want to refresh when submit is triggered, I add prevent
I write a custom form verification instruction for myself
related code
.vue page
<template>
<div>
1_1
<form novalidate @submit.stop.prevent.self v-submit="dosubmit()" >
<input type="text" v-model="a" name="a" required minlength="2" maxlength="6" pattern="/^\d*$/" />
<input type="submit" value="" />
</form>
</div>
</template>
<script>
export default {
name: "caidan1_1",
data () {
return {
a:""
}
},
methods:{
dosubmit:function(){
debugger
console.log(this.a);
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
and my custom instructions, I haven"t finished yet. Please don"t.
import Vue from "vue";
const types=["checkbox","color","date","datetime","datetime-local","month","week","time","email","file","hidden","number","password","radio","range","search","tel","text","url"];
Vue.directive("submit",{
bind:function(el,binding,vnode,oldVnode){
},
inserted:function(el,binding,vnode,oldVnode){
debugger
el.addEventListener("submit",function(){
scope[fn.replace(/\(.*\)/,"")]();
});
const scope=vnode.context;
const fn=binding.expression;
const vModelList=[];
},
update:function(el,binding,vnode,oldVnode){},
componentUpdated:function(el,binding,vnode,oldVnode){},
unbind:function(el,binding,vnode,oldVnode){}
});