{"id":426565,"date":"2024-07-18T15:00:09","date_gmt":"2024-07-18T15:00:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=426565"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=426565","title":{"rendered":"<span>Vue router layouts<\/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>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <strong>layout<\/strong> \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 <strong>Vue<\/strong> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <strong>Vue router<\/strong>.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 <strong>Vue2 options api<\/strong> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>Vue Router v3.<\/strong> \u0412 \u0442\u0435\u043e\u0440\u0438\u0438 \u043d\u0435 \u0432\u0438\u0436\u0443 \u043e\u0441\u043e\u0431\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0434\u043b\u044f <strong>Vue3<\/strong> \u0441 <strong>composition api<\/strong>.<\/p>\n<blockquote>\n<p><a href=\"https:\/\/github.com\/TorusHelm\/vue-router-layout\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439<\/a><\/p>\n<\/blockquote>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430<\/strong>: \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u043f\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c <strong>layout<\/strong> \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0434\u043b\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0439 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 <strong>nuxt3<\/strong>.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <strong>@\/layouts<\/strong><\/p>\n<p>\u041e\u0444\u043e\u0440\u043c\u043b\u044f\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d:<\/p>\n<pre><code class=\"javascript\">\/\/ @\/layouts\/index.vue &lt;template> &lt;component :is=\"layoutComponent\"> &lt;\/template>  &lt;script> import \"\u041d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441 \u043b\u0435\u0439\u0430\u0443\u0442\u043e\u043c\"  export default { name: \"layout\", components: { \u041d\u0430\u0448\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b layout }, computed: { \/\/ \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0438\u043c\u044f \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043d\u0430\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \/\/ \u043d\u0435 \u0434\u0435\u043b\u0430\u044e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0442\u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441 \u043b\u0435\u0439\u0430\u0443\u0442\u0430\u043c\u0438  \/\/ \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043d\u0435 \u043c\u043d\u043e\u0433\u043e, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c      layoutComponent() {       return `layout-${this.layoutType}`;     },          routeHaveLayoutType() {       return this.$route.meta &amp;&amp; 'layout' in this.$route.meta;     },          \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u0430\u043e\u0439 layout \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c     \/\/ \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c $router.meta, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e default     \/\/ \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u043e \u043d\u0430\u0448\u0435\u043c\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 &lt;layout-default \/>     layoutType() {       if (this.routeHaveLayoutType) {         return this.$route.meta.layout;       }       return \"default\";     }, } } &lt;\/script><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0440\u044f\u0434\u043e\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 <strong>@\/layouts\/components<\/strong><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c <strong>default<\/strong> \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">\/\/ @\/layouts\/components\/default.vue &lt;template>   \/\/ \u0412\u0430\u0448\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0434\u043b\u044f default layout   \/\/ \u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0430\u044f \u0432 \u0441\u0435\u0431\u044f router-view    \/\/ \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440   &lt;div class=\"container\">   &lt;header>My header&lt;\/header>   &lt;main>   &lt;router-view \/>   &lt;\/main>   &lt;footer>My footer&lt;\/footer>   &lt;\/div> &lt;\/template><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d <strong>tabs<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0442\u0430\u0431\u043e\u0432, \u0433\u0434\u0435 \u0442\u0430\u0431\u044b &#8212; \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443:<\/p>\n<pre><code class=\"javascript\">\/\/ @\/layouts\/components\/tabs &lt;template>   &lt;div class=\"container\">     &lt;div class=\"tabs\">       &lt;RouterLink           v-for=\"(tab, index) in tabs\"           :key=\"index\"           :to=\"tab.path\"           class=\"tabs__item\"           active-class=\"is-active\"       >         {{ tab.title }}       &lt;\/RouterLink>     &lt;\/div>     &lt;div class=\"tabs__content\">       &lt;router-view \/>     &lt;\/div>   &lt;\/div> &lt;\/template>  &lt;script> export default {   name: \"LayoutTabs\",   props: {     tabs: {       type: Array,       default: () => [],     },   }, } &lt;\/script><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d <strong>extra<\/strong> \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ @\/layouts\/components\/extra &lt;template>   &lt;div class=\"container\">     &lt;heading>Extra layout&lt;\/heading>     &lt;router-view>&lt;\/router-view>   &lt;\/div> &lt;\/template><\/code><\/pre>\n<p>\u0412 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e <strong>App.vue<\/strong> \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>&lt;layout \/><\/strong> \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e <strong>&lt;router-view\/><\/strong><\/p>\n<pre><code class=\"javascript\">&lt;template>   &lt;div id=\"app\">     \/\/ \u0411\u044b\u043b\u043e   \/\/ &lt;router-view \/>      \/\/ \u0421\u0442\u0430\u043b\u043e     &lt;layout \/>   &lt;\/div> &lt;\/template><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <strong>router<\/strong>, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <a href=\"https:\/\/v3.router.vuejs.org\/guide\/#javascript\" rel=\"noopener noreferrer nofollow\"><strong>vue-router<\/strong><\/a>, \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e:<\/p>\n<pre><code class=\"javascript\">const routes = [ { path: \"\/\", component: () => import(\u0412\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b), ... } ... ]<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e\u0433\u043e <strong>layout<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>router.meta<\/strong>:<\/p>\n<pre><code class=\"javascript\">{ path: \"\/\", components: () => import(\u0412\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442), meta: { layout: \"extra\", }, }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043e\u0432 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>router.meta<\/strong> \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c <strong>route<\/strong>, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 \u043d\u0430\u0448\u0435\u043c <strong>@\/layouts\/index<\/strong>:<\/p>\n<pre><code class=\"javascript\">&lt;template>   &lt;component :is=\"layoutComponent\" :tabs=\"layoutTabs\" :parentRoute=\"parentRoute\" \/> &lt;\/template>  &lt;script> import LayoutDefault from \".\/components\/default.vue\"; import LayoutExtra from \".\/components\/extra.vue\"; import LayoutTabs from \".\/components\/tabs.vue\";  export default {   name: \"Layout\",   components: {     LayoutDefault,     LayoutExtra,     LayoutTabs,   },   computed: {     routeHaveLayoutType() {       return this.$route.meta &amp;&amp; 'layout' in this.$route.meta;     },     parentRouteHaveLayoutType() {       return this.parentRoute &amp;&amp; this.parentRoute.meta &amp;&amp; 'layout' in this.parentRoute.meta;     },     routeHaveLayoutTabs() {       return this.$route.meta &amp;&amp; 'layoutTabs' in this.$route.meta;     },     parentRouteHaveLayoutTabs() {       return this.parentRoute &amp;&amp; this.parentRoute.meta &amp;&amp; 'layoutTabs' in this.parentRoute.meta;     },     layoutType() {       \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 route layout       if (this.routeHaveLayoutType) {         return this.$route.meta.layout;       }              \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 route layout       if (this.parentRouteHaveLayoutType) {         return this.parentRoute.meta.layout;       }              \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0435\u0441\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0448\u043b\u0438       return \"default\";     },     layoutComponent() {       return `layout-${this.layoutType}`;     },     layoutTabs() {       if (this.layoutType === 'tabs') {       \/\/ \u0435\u0441\u043b\u0438 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c route \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0442\u0430\u0431\u044b \u0434\u043b\u044f layout \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u0445         if (this.routeHaveLayoutTabs) {           return this.$route.meta.layoutTabs;         }                  \/\/ \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043e\u0432 \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c route         if (this.parentRouteHaveLayoutTabs) {           return this.parentRoute.meta.layoutTabs;         }         return [];       }       return [];     },          \/\/ \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 route     parentRoute() {       const currentInMatched = this.$route.matched.find(i => i.regex.test(this.$route.path));       return currentInMatched &amp;&amp; currentInMatched.parent;     }   }, } &lt;\/script> <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 <strong>Vue<\/strong> \u0438 <strong>Vue-router<\/strong>, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c\u0441\u044f \u043a <strong>children<\/strong> \u0438 \u0438\u0437 \u043d\u0438\u0445 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u0442\u0430\u0431\u043e\u0432, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u043c computed \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 <strong>&lt;layout\/><\/strong>:<\/p>\n<pre><code class=\"javascript\">{ computed: { ...       layoutTabs() {       \/\/ \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 parentRoute.children \u043a\u0430\u043a \u0442\u0430\u0431\u044b       if (this.parentChildren) {         return this.parentChildren.map((i, k) => {           return {             path: i.path,             title: 'tabTitle' in i.meta &amp;&amp; i.meta.tabTitle || `tab${k}`,           }         });       }        \/\/ \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0442\u0430\u0431\u043e\u0432 \u043a\u0430\u043a meta.layoutTabs       if (this.layoutType === 'tabs') {         if (this.routeHaveLayoutTabs) {           return this.$route.meta.layoutTabs;         }         if (this.parentRouteHaveLayoutTabs) {           return this.parentRoute.meta.layoutTabs;         }         return [];       }       return [];     },          \/\/ \u043d\u0430\u0445\u043e\u0434\u0438\u043c children \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e route     parentChildren() {       if (!this.parentRoute) return [];       const parentRoute = this.$router.options.routes.find(i => this.parentRoute.regex.test(i.path) );       return parentRoute &amp;&amp; parentRoute.children;     }, } }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 route \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e <strong>layout<\/strong> \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 <strong>route<\/strong> \u043e\u0444\u043e\u0440\u043c\u043b\u044f\u0435\u043c \u043a\u043e\u0434 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<pre><code class=\"javascript\">[ { path: \"default\", component: () => import(\"\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), }, { path: \"tabs\", redirect: \"\/tabs\/red\", meta: { layout: \"tabs\", layoutTabs: \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u0430\u0431\u043e\u0432 \/\/ \u0435\u0441\u043b\u0438 \u0431\u0435\u0440\u0435\u043c \u0442\u0430\u0431\u044b \u0438\u0437 meta }, children: [ { path: \"red\", component: () => import(\"\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e &lt;router-view \/>\"), \/\/ \u043a\u0435\u0439\u0441 \u0441 \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e route \"red\" children: [ { \/\/ \u0434\u043b\u044f \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u0440\u043e\u0443\u0442\u0430 \"red\" path: \"\", component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 red \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), }, { path: \"orange\", component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 oragne \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), meta: { layout: \"extra\", }, }, { path: \"tomato\", component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 tomato \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), meta: { layout: \"extra\", }, } ], }, { path: \"green\" component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 green \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), }, { path: \"blue\", component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 blue \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), } ] } ]<\/code><\/pre>\n<blockquote>\n<p>\u041f\u043e\u043b\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/TorusHelm\/vue-router-layout\" rel=\"noopener noreferrer nofollow\">Github<\/a><\/p>\n<\/blockquote>\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\/829650\/\"> https:\/\/habr.com\/ru\/articles\/829650\/<\/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>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <strong>layout<\/strong> \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 <strong>Vue<\/strong> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <strong>Vue router<\/strong>.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 <strong>Vue2 options api<\/strong> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <strong>Vue Router v3.<\/strong> \u0412 \u0442\u0435\u043e\u0440\u0438\u0438 \u043d\u0435 \u0432\u0438\u0436\u0443 \u043e\u0441\u043e\u0431\u044b\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0434\u043b\u044f <strong>Vue3<\/strong> \u0441 <strong>composition api<\/strong>.<\/p>\n<blockquote>\n<p><a href=\"https:\/\/github.com\/TorusHelm\/vue-router-layout\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439<\/a><\/p>\n<\/blockquote>\n<p><strong>\u0417\u0430\u0434\u0430\u0447\u0430<\/strong>: \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u0441\u0442\u0440\u0430\u043d\u0438\u0446 \u043f\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c <strong>layout<\/strong> \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0434\u043b\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0439 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 <strong>nuxt3<\/strong>.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <strong>@\/layouts<\/strong><\/p>\n<p>\u041e\u0444\u043e\u0440\u043c\u043b\u044f\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d:<\/p>\n<pre><code class=\"javascript\">\/\/ @\/layouts\/index.vue &lt;template> &lt;component :is=\"layoutComponent\"> &lt;\/template>  &lt;script> import \"\u041d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441 \u043b\u0435\u0439\u0430\u0443\u0442\u043e\u043c\"  export default { name: \"layout\", components: { \u041d\u0430\u0448\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b layout }, computed: { \/\/ \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0438\u043c\u044f \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043d\u0430\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \/\/ \u043d\u0435 \u0434\u0435\u043b\u0430\u044e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0442\u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441 \u043b\u0435\u0439\u0430\u0443\u0442\u0430\u043c\u0438  \/\/ \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043d\u0435 \u043c\u043d\u043e\u0433\u043e, \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c      layoutComponent() {       return `layout-${this.layoutType}`;     },          routeHaveLayoutType() {       return this.$route.meta &amp;&amp; 'layout' in this.$route.meta;     },          \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u0430\u043e\u0439 layout \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c     \/\/ \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c $router.meta, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e default     \/\/ \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u043e \u043d\u0430\u0448\u0435\u043c\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443 &lt;layout-default \/>     layoutType() {       if (this.routeHaveLayoutType) {         return this.$route.meta.layout;       }       return \"default\";     }, } } &lt;\/script><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0440\u044f\u0434\u043e\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 <strong>@\/layouts\/components<\/strong><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c <strong>default<\/strong> \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">\/\/ @\/layouts\/components\/default.vue &lt;template>   \/\/ \u0412\u0430\u0448\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0434\u043b\u044f default layout   \/\/ \u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0430\u044f \u0432 \u0441\u0435\u0431\u044f router-view    \/\/ \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440   &lt;div class=\"container\">   &lt;header>My header&lt;\/header>   &lt;main>   &lt;router-view \/>   &lt;\/main>   &lt;footer>My footer&lt;\/footer>   &lt;\/div> &lt;\/template><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d <strong>tabs<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0442\u0430\u0431\u043e\u0432, \u0433\u0434\u0435 \u0442\u0430\u0431\u044b &#8212; \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443:<\/p>\n<pre><code class=\"javascript\">\/\/ @\/layouts\/components\/tabs &lt;template>   &lt;div class=\"container\">     &lt;div class=\"tabs\">       &lt;RouterLink           v-for=\"(tab, index) in tabs\"           :key=\"index\"           :to=\"tab.path\"           class=\"tabs__item\"           active-class=\"is-active\"       >         {{ tab.title }}       &lt;\/RouterLink>     &lt;\/div>     &lt;div class=\"tabs__content\">       &lt;router-view \/>     &lt;\/div>   &lt;\/div> &lt;\/template>  &lt;script> export default {   name: \"LayoutTabs\",   props: {     tabs: {       type: Array,       default: () => [],     },   }, } &lt;\/script><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0431\u043b\u043e\u043d <strong>extra<\/strong> \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ @\/layouts\/components\/extra &lt;template>   &lt;div class=\"container\">     &lt;heading>Extra layout&lt;\/heading>     &lt;router-view>&lt;\/router-view>   &lt;\/div> &lt;\/template><\/code><\/pre>\n<p>\u0412 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e <strong>App.vue<\/strong> \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 <strong>&lt;layout \/><\/strong> \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e <strong>&lt;router-view\/><\/strong><\/p>\n<pre><code class=\"javascript\">&lt;template>   &lt;div id=\"app\">     \/\/ \u0411\u044b\u043b\u043e   \/\/ &lt;router-view \/>      \/\/ \u0421\u0442\u0430\u043b\u043e     &lt;layout \/>   &lt;\/div> &lt;\/template><\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <strong>router<\/strong>, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <a href=\"https:\/\/v3.router.vuejs.org\/guide\/#javascript\" rel=\"noopener noreferrer nofollow\"><strong>vue-router<\/strong><\/a>, \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e:<\/p>\n<pre><code class=\"javascript\">const routes = [ { path: \"\/\", component: () => import(\u0412\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b), ... } ... ]<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e\u0433\u043e <strong>layout<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>router.meta<\/strong>:<\/p>\n<pre><code class=\"javascript\">{ path: \"\/\", components: () => import(\u0412\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442), meta: { layout: \"extra\", }, }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043e\u0432 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>router.meta<\/strong> \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c <strong>route<\/strong>, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 \u043d\u0430\u0448\u0435\u043c <strong>@\/layouts\/index<\/strong>:<\/p>\n<pre><code class=\"javascript\">&lt;template>   &lt;component :is=\"layoutComponent\" :tabs=\"layoutTabs\" :parentRoute=\"parentRoute\" \/> &lt;\/template>  &lt;script> import LayoutDefault from \".\/components\/default.vue\"; import LayoutExtra from \".\/components\/extra.vue\"; import LayoutTabs from \".\/components\/tabs.vue\";  export default {   name: \"Layout\",   components: {     LayoutDefault,     LayoutExtra,     LayoutTabs,   },   computed: {     routeHaveLayoutType() {       return this.$route.meta &amp;&amp; 'layout' in this.$route.meta;     },     parentRouteHaveLayoutType() {       return this.parentRoute &amp;&amp; this.parentRoute.meta &amp;&amp; 'layout' in this.parentRoute.meta;     },     routeHaveLayoutTabs() {       return this.$route.meta &amp;&amp; 'layoutTabs' in this.$route.meta;     },     parentRouteHaveLayoutTabs() {       return this.parentRoute &amp;&amp; this.parentRoute.meta &amp;&amp; 'layoutTabs' in this.parentRoute.meta;     },     layoutType() {       \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 route layout       if (this.routeHaveLayoutType) {         return this.$route.meta.layout;       }              \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 route layout       if (this.parentRouteHaveLayoutType) {         return this.parentRoute.meta.layout;       }              \/\/ \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0435\u0441\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0448\u043b\u0438       return \"default\";     },     layoutComponent() {       return `layout-${this.layoutType}`;     },     layoutTabs() {       if (this.layoutType === 'tabs') {       \/\/ \u0435\u0441\u043b\u0438 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c route \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0442\u0430\u0431\u044b \u0434\u043b\u044f layout \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u0445         if (this.routeHaveLayoutTabs) {           return this.$route.meta.layoutTabs;         }                  \/\/ \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043e\u0432 \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c route         if (this.parentRouteHaveLayoutTabs) {           return this.parentRoute.meta.layoutTabs;         }         return [];       }       return [];     },          \/\/ \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 route     parentRoute() {       const currentInMatched = this.$route.matched.find(i => i.regex.test(this.$route.path));       return currentInMatched &amp;&amp; currentInMatched.parent;     }   }, } &lt;\/script> <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0430 <strong>Vue<\/strong> \u0438 <strong>Vue-router<\/strong>, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c\u0441\u044f \u043a <strong>children<\/strong> \u0438 \u0438\u0437 \u043d\u0438\u0445 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u0442\u0430\u0431\u043e\u0432, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u043c computed \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 <strong>&lt;layout\/><\/strong>:<\/p>\n<pre><code class=\"javascript\">{ computed: { ...       layoutTabs() {       \/\/ \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 parentRoute.children \u043a\u0430\u043a \u0442\u0430\u0431\u044b       if (this.parentChildren) {         return this.parentChildren.map((i, k) => {           return {             path: i.path,             title: 'tabTitle' in i.meta &amp;&amp; i.meta.tabTitle || `tab${k}`,           }         });       }        \/\/ \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0442\u0430\u0431\u043e\u0432 \u043a\u0430\u043a meta.layoutTabs       if (this.layoutType === 'tabs') {         if (this.routeHaveLayoutTabs) {           return this.$route.meta.layoutTabs;         }         if (this.parentRouteHaveLayoutTabs) {           return this.parentRoute.meta.layoutTabs;         }         return [];       }       return [];     },          \/\/ \u043d\u0430\u0445\u043e\u0434\u0438\u043c children \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e route     parentChildren() {       if (!this.parentRoute) return [];       const parentRoute = this.$router.options.routes.find(i => this.parentRoute.regex.test(i.path) );       return parentRoute &amp;&amp; parentRoute.children;     }, } }<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 route \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e <strong>layout<\/strong> \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 <strong>route<\/strong> \u043e\u0444\u043e\u0440\u043c\u043b\u044f\u0435\u043c \u043a\u043e\u0434 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435:<\/p>\n<pre><code class=\"javascript\">[ { path: \"default\", component: () => import(\"\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), }, { path: \"tabs\", redirect: \"\/tabs\/red\", meta: { layout: \"tabs\", layoutTabs: \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u0430\u0431\u043e\u0432 \/\/ \u0435\u0441\u043b\u0438 \u0431\u0435\u0440\u0435\u043c \u0442\u0430\u0431\u044b \u0438\u0437 meta }, children: [ { path: \"red\", component: () => import(\"\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e &lt;router-view \/>\"), \/\/ \u043a\u0435\u0439\u0441 \u0441 \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e route \"red\" children: [ { \/\/ \u0434\u043b\u044f \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u0440\u043e\u0443\u0442\u0430 \"red\" path: \"\", component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 red \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), }, { path: \"orange\", component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 oragne \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), meta: { layout: \"extra\", }, }, { path: \"tomato\", component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 tomato \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), meta: { layout: \"extra\", }, } ], }, { path: \"green\" component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 green \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), }, { path: \"blue\", component: () => import(\"\u0432\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 blue \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b\"), } ] } ]<\/code><\/pre>\n<blockquote>\n<p>\u041f\u043e\u043b\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 <a href=\"https:\/\/github.com\/TorusHelm\/vue-router-layout\" rel=\"noopener noreferrer nofollow\">Github<\/a><\/p>\n<\/blockquote>\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\/829650\/\"> https:\/\/habr.com\/ru\/articles\/829650\/<\/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-426565","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/426565","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=426565"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/426565\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=426565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=426565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=426565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}