我这里用到了 vue3 和 elementplus,有如下的点击事件
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
<el-button @click="resetForm('ruleForm')">重置</el-button>
</el-form-item>
在电脑端这俩执行都是没有问题的,但在手机端,我用的chrome只有重置有反应,创建的代码:
submitForm(ruleForm) {
const _this = this
alert("ssss")
this.$refs[ruleForm].validate((valid) => {
if (valid) {
this.$axios.post("/login", this.ruleForm).then((result) => {
const token = result.headers['Authorization']
_this.$store.commit('SET_TOKEN', token)
_this.$store.commit('SET_USERINFO', result.data.data)
_this.$router.push("/exercise")
})
} else {
console.log('error submit!!');
return false;
}
});
},
axios拦截的代码:
axios.interceptors.response.use(response => {
let res = response.data;
if (res.code === 200){
return response
} else {
ElMessage.error('工号或姓名错误!')
return Promise.reject(response.data.msg)
}
},
你在点击事件 alert("") 一下 看看 是否执行 。连alert都没执行吗?
你这是vue3 和 vue2 混合使用的嘛? 只能是你的 if (valid) 条件没有成立
推荐你还是 如果用了vue3 整体就全部用vue3的方式吧,不然或多或少的还是会出现一些兼容性问题,
参考element-plus使用对应的 ref方式获取节点去使用吧 现在不排除是你的ref属性没有获取到 排查一下吧