【发布时间】:2019-09-30 13:33:54
【问题描述】:
我正在使用 Veevalidate 和 Buefy 在 POST 请求之前验证表单。我能够正确验证表单,但 POST 请求方法在验证之前运行。
我对如何按顺序调用方法有点困惑:
- 验证表单
- POST 请求
代码沙盒:https://codesandbox.io/s/mj1vy2vq0j
代码概览
<b-modal>
<form @submit.prevent="validateBeforeSubmit">
...
...
<button type="submit" class="button is-primary" @click="postItem()">Submit</button>
<button type="button" class="button" @click="isAddModalActive=false">Cancel</button>
</form>
</b-modal>
<script>
...
methods: {
validateBeforeSubmit() {
this.$validator.validateAll().then(result => {
if (result) {
this.$toast.open({
message: "Form is valid!",
type: "is-success",
position: "is-bottom"
});
}
this.$toast.open({
message: "Form is not valid! Please check the fields.",
type: "is-danger",
position: "is-bottom"
});
});
},
postItem() {
alert("postItem function was called");
}
}
</script>
【问题讨论】:
标签: vue.js vee-validate buefy