Created
June 5, 2021 10:40
-
-
Save isaacssemugenyi/deb12cdc14460317919555d9502170eb to your computer and use it in GitHub Desktop.
import yup in your ArticleForm component and define a validation schema, (ArticleSchema)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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