我开始学习Nuxt.js,我喜欢Nuxt.js!
但我遇到了问题:
我想为我的应用程序的所有页面创建页眉和页脚布局(模拟:extends layout
for pug)。
我找到了以下方式(nuxt.config.js
):
router: {
extendRoutes(routes, resolve) {
routes.push({
name: 'custom',
path: '*',
component: resolve(__dirname, 'layouts/header.vue')
})
}
},
但它不适合我。 :(
我找到了文档(click me):
<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
<head>
{{ HEAD }}
</head>
<body {{ BODY_ATTRS }}>
{{ APP }}
</body>
</html>
我想要设置选项,每个页面加载我的模式:
<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
<head>
{{ HEAD }}
</head>
<body {{ BODY_ATTRS }}>
{{ HEADER}}
{{ APP }}
{{ FOOTER}}
</body>
</html>
是否有可能在Nuxt.js中做类似的事情?
只需要在布局目录下准备布局
并为页眉和页脚准备2个组件
所以,布局模板将如下所示
<template>
<header_component>
</header_component>
</Nuxt>
<footer_component>
</footer_component>
</template>