Skip to content

Instantly share code, notes, and snippets.

@isaacssemugenyi
Created June 5, 2021 10:40
Show Gist options
  • Save isaacssemugenyi/deb12cdc14460317919555d9502170eb to your computer and use it in GitHub Desktop.
Save isaacssemugenyi/deb12cdc14460317919555d9502170eb to your computer and use it in GitHub Desktop.
import yup in your ArticleForm component and define a validation schema, (ArticleSchema)
<script>
import * as Yup from "yup";
const ArticleSchema = Yup.object().shape({
title: Yup.string()
.min(10, "Title should be less than 10 characters")
.max(100, "Title should not exceed 100 characters")
.required("Title is required"),
description: Yup.string()
.min(50, "Description should be less than 50 characters")
.max(1000, "Description should not exceed 1000 characters")
.required("Description is required"),
});
export default {
name: "ArticleForm",
data() {
return {
article: {
title: "",
description: "",
},
};
},
methods: {
submitData() {
const submittedData = `${this.article.title} ${this.article.description}`;
alert(submittedData);
},
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment