{"id":351167,"date":"2023-08-02T21:00:48","date_gmt":"2023-08-02T21:00:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=351167"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=351167","title":{"rendered":"<span>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0444\u043e\u0440\u043c\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AJV, Vue.js \u0438 TypeScript<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0444\u043e\u0440\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u043f\u044b\u0442 \u0438 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 AJV \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 Vue.js \u0438 TypeScript \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0449\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 AJV?<\/h2>\n<p><a href=\"https:\/\/ajv.js.org\/\" rel=\"noopener noreferrer nofollow\">AJV (Another JSON Schema Validator)<\/a> &#8212; \u044d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 JSON Schema. <a href=\"https:\/\/json-schema.org\/\" rel=\"noopener noreferrer nofollow\">JSON Schema<\/a> &#8212; \u044d\u0442\u043e \u044f\u0437\u044b\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON. AJV \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0441\u0445\u0435\u043c\u0430\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h2>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043d\u0430\u0447\u0430\u0442\u044c, \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c:<\/p>\n<ol>\n<li>\n<p>Node.js v18.16.1.<\/p>\n<\/li>\n<li>\n<p>@vue\/cli 5.0.8<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Vue CLI \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:<\/p>\n<pre><code>vue create ajv-validation<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7fe\/3c8\/4bc\/7fe3c84bcb32c567f38936fcb8f49143.png\" width=\"963\" height=\"210\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7fe\/3c8\/4bc\/7fe3c84bcb32c567f38936fcb8f49143.png\"\/><\/figure>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435:<\/p>\n<pre><code>npm install ajv ajv-formats ajv-errors<\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0441\u0445\u0435\u043c\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 login.json<\/h2>\n<details class=\"spoiler\">\n<summary>login.json<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>{   \"$id\": \"\/login.json\",   \"type\": \"object\",   \"additionalProperties\": false,   \"required\": [\"login\", \"password\"],   \"properties\": {     \"login\": {       \"type\": \"string\",       \"format\": \"email\",       \"errorMessage\": \"enter a valid email address\"     },     \"password\": {       \"type\": \"string\",       \"minLength\": 6,       \"maxLength\": 1024     }   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0442\u0438\u043f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044f (\u0441\u0442\u0440\u043e\u043a\u0430), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0444\u043e\u0440\u043c\u0430\u0442 email \u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0430\u0440\u043e\u043b\u044f. \u041f\u043e\u043b\u044f &#171;login&#187; \u0438 &#171;password&#187; \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<h2>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043a\u0440\u0430\u0442\u043a\u043e \u043f\u0440\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u043f\u043e 2 \u0432\u0430\u0436\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c:<\/h2>\n<p>onLogin \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0432\u0445\u043e\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 (\u043b\u043e\u0433\u0438\u043d\u0435). \u041e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 validate. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0445\u0435\u043c\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u0435. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0444\u043b\u0430\u0433 isValid, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043f\u0440\u043e\u0448\u043b\u0430 \u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b (isValid \u0440\u0430\u0432\u0435\u043d false), \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>function onLogin()<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>function onLogin() {       errors.value.clear();       if (validator.validate(\"\/login.json\", formData.value)) {         \/\/ valid, do nothing       } else if (validator.errors?.length) {         for (const [, e] of validator.errors.entries()) {           if (!e.message) {             continue;           }           const fieldName = e.instancePath.substring(1);           const fieldErrors: string[] = errors.value.get(fieldName) || [];           fieldErrors.push(e.message);           errors.value.set(fieldName, fieldErrors);         }       }     }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>onBlur \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0438 &#171;blur&#187; (\u043f\u043e\u0442\u0435\u0440\u044f \u0444\u043e\u043a\u0443\u0441\u0430) \u043d\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u043f\u043e\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0441 \u043f\u043e\u043b\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b \u0438\u043b\u0438 \u0449\u0435\u043b\u043a\u0430\u0435\u0442 \u0432\u043d\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f.<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043c\u044f (\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440) \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0432\u0432\u043e\u0434\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 &#171;blur&#187;.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0445\u0435\u043c\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f \u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 validate.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e (isValid \u0440\u0430\u0432\u0435\u043d false), \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>function onBlur()<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>function onBlur(e: any) {       const fieldName = e.target.id;       const fieldValue = e.target.value;       if (         validator.validate(`\/login.json#\/properties\/${fieldName}`, fieldValue)       ) {         errors.value.delete(fieldName);       } else if (validator.errors?.length) {         errors.value.set(           fieldName,           validator.errors.map((e) => e.message) as string[]         );       }     }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c AJV \u0441 Vue.js \u0438 TypeScript \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0449\u043d\u044b\u0435 \u0438 \u0433\u0438\u0431\u043a\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u043f\u044b\u0442 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<h2>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/h2>\n<details class=\"spoiler\">\n<summary>App.vue<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>&lt;template>   &lt;div class=\"login-form\">     &lt;h2>Login&lt;\/h2>     &lt;form @submit.prevent=\"onLogin\">       &lt;div class=\"form-group\">         &lt;label for=\"login\">Email&lt;\/label>         &lt;input           v-model=\"formData.login\"           :class=\"{ 'is-invalid': isInvalid(errors.has('login')) }\"           @blur=\"onBlur\"           type=\"text\"           id=\"login\"           placeholder=\"Enter your email\"         \/>         &lt;ul class=\"error-wrapper\">           &lt;li v-for=\"errorMsg of errors.get('login')\" :key=\"errorMsg\">             {{ errorMsg }}           &lt;\/li>         &lt;\/ul>       &lt;\/div>        &lt;div class=\"form-group\">         &lt;label for=\"password\">Password&lt;\/label>         &lt;input           v-model=\"formData.password\"           :class=\"{ 'is-invalid': isInvalid(errors.has('password')) }\"           @blur=\"onBlur\"           type=\"password\"           id=\"password\"           placeholder=\"Enter your password\"         \/>          &lt;ul class=\"error-wrapper\">           &lt;li v-for=\"errorMsg of errors.get('password')\" :key=\"errorMsg\">             {{ errorMsg }}           &lt;\/li>         &lt;\/ul>       &lt;\/div>        &lt;button type=\"submit\" :disabled=\"errors.size > 0\" @click=\"submit('ok')\">         Login       &lt;\/button>     &lt;\/form>   &lt;\/div> &lt;\/template>  &lt;script lang=\"ts\"> import { defineComponent, ref, watch } from \"vue\"; import login from \"@\/schemas\/login.json\"; import Ajv from \"ajv\"; import ajvFormats from \"ajv-formats\"; import ajvErrors from \"ajv-errors\";  export default defineComponent({   setup() {     const formData = ref({       login: \"\",       password: \"\",     });      const opts = { allErrors: true };     const validator = ajvErrors(ajvFormats(new Ajv(opts)));     validator.addSchema(login);      let errors = ref&lt;Map&lt;string, string[]>>(new Map());     watch(       () => errors.value,       () => void 0     );      function onBlur(e: any) {       const fieldName = e.target.id;       const fieldValue = e.target.value;       if (         validator.validate(`\/login.json#\/properties\/${fieldName}`, fieldValue)       ) {         errors.value.delete(fieldName);       } else if (validator.errors?.length) {         errors.value.set(           fieldName,           validator.errors.map((e) => e.message) as string[]         );       }     }      function onLogin() {       errors.value.clear();       if (validator.validate(\"\/login.json\", formData.value)) {         \/\/ valid, do nothing       } else if (validator.errors?.length) {         for (const [, e] of validator.errors.entries()) {           if (!e.message) {             continue;           }           const fieldName = e.instancePath.substring(1);           const fieldErrors: string[] = errors.value.get(fieldName) || [];           fieldErrors.push(e.message);           errors.value.set(fieldName, fieldErrors);         }       }     }      function formColor(error: any) {       return error?.length;     }      function submit(text: string) {       alert(text);     }      return {       formData,       errors,       isInvalid: formColor,       onBlur,       onLogin,       submit,     };   }, }); &lt;\/script>  &lt;style> body {   font-family: sans-serif; }  .login-form {   max-width: 300px;   margin: 0 auto;   padding: 20px;   border: 1px solid #ccc;   border-radius: 5px;   background-color: #f9f9f9; }  .login-form h2 {   text-align: center;   margin-bottom: 20px; }  .form-group {   margin-bottom: 20px; }  label {   display: block;   font-weight: bold;   margin-bottom: 5px; }  input {   width: 100%;   padding: 8px;   border: 1px solid #ccc;   border-radius: 5px; }  button {   width: 100%;   padding: 10px;   background-color: #007bff;   color: #fff;   border: none;   border-radius: 5px;   cursor: pointer;   transition: background-color 0.3s ease; }  button:hover {   background-color: #0056b3; }  button:disabled {   background-color: #ccc; }  .is-invalid {   border: 1px solid red; }  .error-wrapper {   color: red;   font-size: 12px;   margin: 0;   padding: 0 20px; } &lt;\/style> <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><a href=\"https:\/\/github.com\/glebanya13\/ajv-validation\" rel=\"noopener noreferrer nofollow\">github<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/752074\/\"> https:\/\/habr.com\/ru\/articles\/752074\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0444\u043e\u0440\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u043f\u044b\u0442 \u0438 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 AJV \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 Vue.js \u0438 TypeScript \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0449\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 AJV?<\/h2>\n<p><a href=\"https:\/\/ajv.js.org\/\" rel=\"noopener noreferrer nofollow\">AJV (Another JSON Schema Validator)<\/a> &#8212; \u044d\u0442\u043e \u0431\u044b\u0441\u0442\u0440\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 JSON Schema. <a href=\"https:\/\/json-schema.org\/\" rel=\"noopener noreferrer nofollow\">JSON Schema<\/a> &#8212; \u044d\u0442\u043e \u044f\u0437\u044b\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON. AJV \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u0441\u0445\u0435\u043c\u0430\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438.<\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h2>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043d\u0430\u0447\u0430\u0442\u044c, \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c:<\/p>\n<ol>\n<li>\n<p>Node.js v18.16.1.<\/p>\n<\/li>\n<li>\n<p>@vue\/cli 5.0.8<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Vue CLI \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438:<\/p>\n<pre><code>vue create ajv-validation<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435:<\/p>\n<pre><code>npm install ajv ajv-formats ajv-errors<\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0441\u0445\u0435\u043c\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 login.json<\/h2>\n<details class=\"spoiler\">\n<summary>login.json<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>{   \"$id\": \"\/login.json\",   \"type\": \"object\",   \"additionalProperties\": false,   \"required\": [\"login\", \"password\"],   \"properties\": {     \"login\": {       \"type\": \"string\",       \"format\": \"email\",       \"errorMessage\": \"enter a valid email address\"     },     \"password\": {       \"type\": \"string\",       \"minLength\": 6,       \"maxLength\": 1024     }   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0442\u0438\u043f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044f (\u0441\u0442\u0440\u043e\u043a\u0430), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0444\u043e\u0440\u043c\u0430\u0442 email \u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0430\u0440\u043e\u043b\u044f. \u041f\u043e\u043b\u044f &#171;login&#187; \u0438 &#171;password&#187; \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<h2>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043a\u0440\u0430\u0442\u043a\u043e \u043f\u0440\u043e\u0439\u0434\u0451\u043c\u0441\u044f \u043f\u043e 2 \u0432\u0430\u0436\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c:<\/h2>\n<p>onLogin \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0432\u0445\u043e\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 (\u043b\u043e\u0433\u0438\u043d\u0435). \u041e\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<ol>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 validate. \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0445\u0435\u043c\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u0435. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0444\u043b\u0430\u0433 isValid, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043f\u0440\u043e\u0448\u043b\u0430 \u043b\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b (isValid \u0440\u0430\u0432\u0435\u043d false), \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>function onLogin()<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>function onLogin() {       errors.value.clear();       if (validator.validate(\"\/login.json\", formData.value)) {         \/\/ valid, do nothing       } else if (validator.errors?.length) {         for (const [, e] of validator.errors.entries()) {           if (!e.message) {             continue;           }           const fieldName = e.instancePath.substring(1);           const fieldErrors: string[] = errors.value.get(fieldName) || [];           fieldErrors.push(e.message);           errors.value.set(fieldName, fieldErrors);         }       }     }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>onBlur \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0438 &#171;blur&#187; (\u043f\u043e\u0442\u0435\u0440\u044f \u0444\u043e\u043a\u0443\u0441\u0430) \u043d\u0430 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u043f\u043e\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u0444\u043e\u0440\u043c\u044b. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0441 \u043f\u043e\u043b\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0444\u043e\u0440\u043c\u044b \u0438\u043b\u0438 \u0449\u0435\u043b\u043a\u0430\u0435\u0442 \u0432\u043d\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044f.<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043c\u044f (\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440) \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0432\u0432\u043e\u0434\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 &#171;blur&#187;.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0445\u0435\u043c\u0443 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044f \u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 validate.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e (isValid \u0440\u0430\u0432\u0435\u043d false), \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>function onBlur()<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>function onBlur(e: any) {       const fieldName = e.target.id;       const fieldValue = e.target.value;       if (         validator.validate(`\/login.json#\/properties\/${fieldName}`, fieldValue)       ) {         errors.value.delete(fieldName);       } else if (validator.errors?.length) {         errors.value.set(           fieldName,           validator.errors.map((e) => e.message) as string[]         );       }     }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c AJV \u0441 Vue.js \u0438 TypeScript \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0449\u043d\u044b\u0435 \u0438 \u0433\u0438\u0431\u043a\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u043f\u044b\u0442 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<h2>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/h2>\n<details class=\"spoiler\">\n<summary>App.vue<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>&lt;template>   &lt;div class=\"login-form\">     &lt;h2>Login&lt;\/h2>     &lt;form @submit.prevent=\"onLogin\">       &lt;div class=\"form-group\">         &lt;label for=\"login\">Email&lt;\/label>         &lt;input           v-model=\"formData.login\"           :class=\"{ 'is-invalid': isInvalid(errors.has('login')) }\"           @blur=\"onBlur\"           type=\"text\"           id=\"login\"           placeholder=\"Enter your email\"         \/>         &lt;ul class=\"error-wrapper\">           &lt;li v-for=\"errorMsg of errors.get('login')\" :key=\"errorMsg\">             {{ errorMsg }}           &lt;\/li>         &lt;\/ul>       &lt;\/div>        &lt;div class=\"form-group\">         &lt;label for=\"password\">Password&lt;\/label>         &lt;input           v-model=\"formData.password\"           :class=\"{ 'is-invalid': isInvalid(errors.has('password')) }\"           @blur=\"onBlur\"           type=\"password\"           id=\"password\"           placeholder=\"Enter your password\"         \/>          &lt;ul class=\"error-wrapper\">           &lt;li v-for=\"errorMsg of errors.get('password')\" :key=\"errorMsg\">             {{ errorMsg }}           &lt;\/li>         &lt;\/ul>       &lt;\/div>        &lt;button type=\"submit\" :disabled=\"errors.size > 0\" @click=\"submit('ok')\">         Login       &lt;\/button>     &lt;\/form>   &lt;\/div> &lt;\/template>  &lt;script lang=\"ts\"> import { defineComponent, ref, watch } from \"vue\"; import login from \"@\/schemas\/login.json\"; import Ajv from \"ajv\"; import ajvFormats from \"ajv-formats\"; import ajvErrors from \"ajv-errors\";  export default defineComponent({   setup() {     const formData = ref({       login: \"\",       password: \"\",     });      const opts = { allErrors: true };     const validator = ajvErrors(ajvFormats(new Ajv(opts)));     validator.addSchema(login);      let errors = ref&lt;Map&lt;string, string[]>>(new Map());     watch(       () => errors.value,       () => void 0     );      function onBlur(e: any) {       const fieldName = e.target.id;       const fieldValue = e.target.value;       if (         validator.validate(`\/login.json#\/properties\/${fieldName}`, fieldValue)       ) {         errors.value.delete(fieldName);       } else if (validator.errors?.length) {         errors.value.set(           fieldName,           validator.errors.map((e) => e.message) as string[]         );       }     }      function onLogin() {       errors.value.clear();       if (validator.validate(\"\/login.json\", formData.value)) {         \/\/ valid, do nothing       } else if (validator.errors?.length) {         for (const [, e] of validator.errors.entries()) {           if (!e.message) {             continue;           }           const fieldName = e.instancePath.substring(1);           const fieldErrors: string[] = errors.value.get(fieldName) || [];           fieldErrors.push(e.message);           errors.value.set(fieldName, fieldErrors);         }       }     }      function formColor(error: any) {       return error?.length;     }      function submit(text: string) {       alert(text);     }      return {       formData,       errors,       isInvalid: formColor,       onBlur,       onLogin,       submit,     };   }, }); &lt;\/script>  &lt;style> body {   font-family: sans-serif; }  .login-form {   max-width: 300px;   margin: 0 auto;   padding: 20px;   border: 1px solid #ccc;   border-radius: 5px;   background-color: #f9f9f9; }  .login-form h2 {   text-align: center;   margin-bottom: 20px; }  .form-group {   margin-bottom: 20px; }  label {   display: block;   font-weight: bold;   margin-bottom: 5px; }  input {   width: 100%;   padding: 8px;   border: 1px solid #ccc;   border-radius: 5px; }  button {   width: 100%;   padding: 10px;   background-color: #007bff;   color: #fff;   border: none;   border-radius: 5px;   cursor: pointer;   transition: background-color 0.3s ease; }  button:hover {   background-color: #0056b3; }  button:disabled {   background-color: #ccc; }  .is-invalid {   border: 1px solid red; }  .error-wrapper {   color: red;   font-size: 12px;   margin: 0;   padding: 0 20px; } &lt;\/style> <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><a href=\"https:\/\/github.com\/glebanya13\/ajv-validation\" rel=\"noopener noreferrer nofollow\">github<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/752074\/\"> https:\/\/habr.com\/ru\/articles\/752074\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-351167","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=351167"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351167\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=351167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=351167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=351167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}