【问题标题】:Does Vue allow template inheritance like Symfony does with Twig?Vue 是否允许像 Symfony 对 Twig 那样的模板继承?
【发布时间】:2018-07-06 08:26:37
【问题描述】:

我希望能够在 Vue 组件的模板中定义块,如下所示:

{# templates/blog/layout.html.twig #}
{% extends 'base.html.twig' %}

{% block body %}
    <h1>Blog Application</h1>
    {% block content %}{% endblock %}
{% endblock %}

然后在不同的组件中使用上面的模板,例如:

{# templates/blog/index.html.twig #}
{% extends 'blog/layout.html.twig' %}

{% block content %}
    {% for entry in blog_entries %}
        <h2>{{ entry.title }}</h2>
        <p>{{ entry.body }}</p>
    {% endfor %}
{% endblock %}

示例来自:https://symfony.com/doc/current/templating/inheritance.html

这可能吗?我已经在使用扩展 API (https://vuejs.org/v2/api/#Vue-extend),但无法覆盖特定块。

谢谢:)

【问题讨论】:

    标签: inheritance vue.js vue-component


    【解决方案1】:

    Vue 本身不允许/不支持,不。

    但是,如果您使用的是 Vue 的 Single File Components,则可以使用支持此功能的模板引擎(如 pug 或 nunjucks)来编写模板。

    要了解如何将 pug 与 vue-loader 一起使用,请参阅 here

    【讨论】:

    猜你喜欢
    • 2012-02-04
    • 2010-12-12
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 2012-06-08
    • 2018-04-04
    • 2017-08-03
    相关资源
    最近更新 更多