布局组件(抽屉、工具栏等)不作为组件工作

Layout components (drawer, toolbar, …) not working as component

我在 vue-material 中使用 vue。

我目前正在设计我的网络应用程序的主要结构,使用 md-app 作为 md-[app-]drawermd-[app-]toolbarmd-[app-]content 的根目录。

如果我将这些组件直接放在 md-app 标签中,它们就可以工作。这看起来像这样:

<template>
  <div class="md-layout-row">
    <md-app>
      <md-drawer>
        <md-list>
          <md-list-item>
            <md-icon>people</md-icon>
            <span class="md-list-item-text">Foo</span>
          </md-list-item>

          <md-list-item>
            <md-icon>view_list</md-icon>
            <span class="md-list-item-text">Bar</span>
          </md-list-item>
        </md-list>
      </md-drawer>
    </md-app>
  </div>
</template>

但出于设计目的,我尝试将每个内部部分(在本例中为 md-drawer 标签)提取到自己的 vue 组件中。

问题

我现在有了 Drawer 组件,它看起来像这样:

<template>
  <md-drawer>
    <md-list>
      <md-list-item>
        <md-icon>people</md-icon>
        <span class="md-list-item-text">Foo</span>
      </md-list-item>

      <md-list-item>
        <md-icon>view_list</md-icon>
        <span class="md-list-item-text">Bar</span>
      </md-list-item>
    </md-list>
  </md-drawer>
</template>

.. 我的 md-app(在导入组件 ofc 之后)现在看起来像这样:

<template>
  <div class="md-layout-row">
    <md-app>
      <MyDrawer />
    </md-app>
  </div>
</template>

但这根本不会渲染抽屉。为什么是这样? Vue 是否额外包装组件可能会与 vue-material 的 css 混淆? bypass/fix这个问题有办法解决吗? .. 还是我用错了?

添加(编辑 1)

经过一些实验,我发现如果用 md-[app-]content 标签包围 MyDrawer 标签,它会起作用,但这不会产生我正在寻找的布局。

我猜 md-app 正在专门寻找这些组件,但因为它不知道如何处理 MyDrawer 标签,所以它只是忽略了它?虽然 MyDrawer 本质上是一个 md-drawer tag/component?

添加(编辑 2)

我一直在阅读有关 DOM Template Parsing Caveats 的内容,我认为这应该可行,但我还没有取得任何成功。我刚刚声明了一个 <md-drawer is="MyDrawer" /> 标签并从 MyDrawer component

中删除了主要包装 md-drawer 标签
  1. 组件使用不当doc

md-active - type = Boolean. Option used to trigger the drawer visibility. Should be used with the .sync modifier. Default = false

用于 Drawer:

的示例
<md-drawer :md-active.sync="showNavigation">
  ...
</md-drawer>
  1. md-app 不正确。见 Component-Naming-Conventions

示例用于 md-app:

<md-app>
  <my-drawer />
</md-app>

*注意 但使用前请看下一个答案

  1. 添加(编辑 1)- 不正确。

Any other tag passed as a direct child of the md-app tag will be ignored. The component will only look for those three tags and choose the right placement for them. Documentation

示例用于 md-app:

<md-app md-waterfall md-mode="fixed-last">
  <md-app-toolbar class="md-large md-dense md-primary">
    <div class="md-toolbar-row">
      <div class="md-toolbar-section-start">
        <md-button class="md-icon-button" @click="menuVisible = !menuVisible">
          <md-icon>menu</md-icon>
        </md-button>
        <span class="md-title">My Title</span>
      </div>

      <div class="md-toolbar-section-end">
        <md-button class="md-icon-button">
          <md-icon>more_vert</md-icon>
        </md-button>
      </div>
    </div>

    <div class="md-toolbar-row">
      <md-tabs class="md-primary">
        <md-tab id="tab-home" md-label="Home"></md-tab>
        <md-tab id="tab-pages" md-label="Pages"></md-tab>
      </md-tabs>
    </div>
  </md-app-toolbar>

  <md-app-drawer :md-active.sync="menuVisible">
    <md-toolbar class="md-transparent" md-elevation="0">Navigation</md-toolbar>
    <md-list>
      <md-list-item>
        <md-icon>move_to_inbox</md-icon>
        <span class="md-list-item-text">Inbox</span>
      </md-list-item>
    </md-list>
  </md-app-drawer>

  <md-app-content>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Error quibusdam, non molestias et! Earum magnam, similique, quo recusandae placeat dicta asperiores modi sint ea repudiandae maxime? Quae non explicabo, neque.</p>
  </md-app-content>
</md-app>
  1. 添加(编辑 2)- 不正确。 is 你的情况无关紧要。 请参阅使用 APIComponent-Naming-Conventions

只需使用标签:<md-drawer/>

更新

如何在 md-app 中使用自定义 Drawer

drawer 必须包裹在 md-app-drawer

例子

代码:

<md-app-drawer :md-active.sync="menuVisible">
  <custom-drawer/>
</md-app-drawer>

App

Component