Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

javascript - Express-Handlebars节的Vue.js等效项是什么?(What is the Vue.js equivalent of Express-Handlebars sections?)

I started a project using Express and Handlebars and then was encouraged to look at Vue.js.

(我使用Express和Handlebars开始了一个项目,然后被鼓励查看Vue.js。)

I am still at the stage of reading the docs but so far can't understand how to have layouts, partials and sections in Vue.js.

(我仍处于阅读文档的阶段,但到目前为止还无法理解如何在Vue.js中使用布局,局部和部分。)

I think a partial would be a component, but I'm lost how to have a layout with partials and sections that I can inject content into.

(我认为局部将是一个组件,但是我迷失了如何将局部和部分布局放入可以注入内容的布局。)

This is what I do using npm express-handlebars in a file called baselayout.hbs :

(这就是我在名为baselayout.hbs的文件中使用npm express-handlebars进行的操作:)

<!doctype html>
<html lang="en">
<head>
    {{> global/headcode }} <!-- partial view with code for the head tag. it has stuff like favicon links --->
    {{{_sections.pagemeta}}} <!-- page specific metadata injected here. this would be meta keywords description etc for a page/view --->
</head>
<body>
<div>
    {{> global/siteheader }} <!--- partial view for the site's header --->

    <div id="base-Container">
        <main id="base-Content" role="main">
            {{{ body }}} <!--- a page's main body content goes here --->
        </main>
    </div>
</div>
{{> sitefooter }} 
{{{_sections.pagescripts}}} <!-- section for page-specific scripts injected here --->
</body>
</html>

How could I setup something like the above in Vue.js that would also work with server-side rendering?

(如何在Vue.js中设置类似上述内容的内容,使其也可以与服务器端渲染一起使用?)

I just need a base layout with header/footer components included but also sections into which page-specific content can go.

(我只需要一个包含页眉/页脚组件的基本布局,还需要一些页面特定内容可以进入的部分。)

  ask by volume one translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You probably need to use components and slots within your components.

(您可能需要使用组件和组件中的插槽。)

Yes you need to create a component for each of your partials.

(是的,您需要为每个零件创建一个组件。)

Each component would have a template.

(每个组件都有一个模板。)

Then you will have a main component that will put all of this together.

(然后,您将有一个主要组件,将所有这些放在一起。)

Using the more granular components you already have (your partials).

(使用您已经拥有的更细粒度的组件(您的局部组件)。)

Now if the template structure (html for each component) is coming from the server then you can prob use slots https://vuejs.org/v2/guide/components-slots.html which is a way VueJs allow components to receive custom markup when instantiating the components (see the example in the docs)

(现在,如果模板结构(每个组件的html)来自服务器,则可以使用插槽 https://vuejs.org/v2/guide/components-slots.html ,这是VueJ允许组件接收自定义标记的方式实例化组件时(请参阅文档中的示例))

For the general layout and UI components of your app you may want to look at https://element.eleme.io/#/en-US/component/layout which is a nice alternative to the more popular Vuetify.

(对于应用程序的常规布局和UI组件,您可能需要查看https://element.eleme.io/#/en-US/component/layout ,它是较流行的Vuetify的不错替代品。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...