【问题标题】:vue-material: unknown custom component md-drawer & md-contentvue-material:未知的自定义组件 md-drawer & md-content
【发布时间】:2018-05-12 16:27:29
【问题描述】:

尝试渲染md-drawer 组件和md-content 组件。但我无法克服这个错误。

[Vue warn]: Unknown custom element: <md-drawer> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

&lt;md-content&gt; 组件有相同的错误消息。

这是代码。

App.vue

<template>
  <div id="app" class="page-container md-layout-column">

      <div class="page-container md-layout-column">
        <md-toolbar class="md-primary">
          <md-button class="md-icon-button" @click="showNavigation = true">
            <md-icon>menu</md-icon>
          </md-button>
        </md-toolbar>

        <md-drawer :md-active.sync="showNavigation">
          <md-toolbar class="md-transparent" md-elevation="0">
            <span class="md-title">My App name</span>
          </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-item>
              <md-icon>send</md-icon>
              <span class="md-list-item-text">Sent Mail</span>
            </md-list-item>

            <md-list-item>
              <md-icon>delete</md-icon>
              <span class="md-list-item-text">Trash</span>
            </md-list-item>

            <md-list-item>
              <md-icon>error</md-icon>
              <span class="md-list-item-text">Spam</span>
            </md-list-item>
          </md-list>
        </md-drawer>

        <md-content>
          <router-view></router-view>
        </md-content>
      </div>
  </div>
</template>

<script>
export default {
  name: "app",
  data: () => ({
    showNavigation: false,
    showSidepanel: false
  })
};
...
<style>...</style>

ma​​in.js

import Vue from 'vue'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import VueMaterial from 'vue-material'

import App from './App.vue'
import store from './store'
import routes from './router'

import 'vue-material/dist/vue-material.css'

const router = new VueRouter({
  routes
})

let colorPrimary = {
  color: 'green',
  hue: 700,
  hexa: '#42b883'
}

let colorAccent = {
  color: 'blue',
  hue: 600,
  hexa: '#35495e'
}

Vue.use(VueMaterial)

Vue.material.registerTheme('default', {
  primary: colorPrimary,
  accent: colorAccent,
  warn: colorPrimary,
  background: 'white'
})

Vue.material.setCurrentTheme('default')

Vue.use(Vuex)
Vue.use(VueRouter)

new Vue({
  el: '#app',
  store,
  router,
  render: h => h(App)
})

您大概可以看出这段代码几乎是从the vue-material docs 直接复制和粘贴的。因此,我几乎可以肯定,问题一定来自main.js,但我看不到,也许其他人可以。

也欢迎任何其他关于我可能做错的事情,或者关于 Vue 的任何事情的额外指示!

【问题讨论】:

  • 你安装的是什么版本的vue-material?我可以告诉您,您链接到的文档的版本与您在代码中的方式不同 register themes

标签: javascript vue.js vuejs2 vue-material


【解决方案1】:

https://vuematerial.io的信息与github不同步。

1) 检查你的 node_modules/vue-material/components/ 看看你有没有文件夹 MdDrawer

2) 你可以看到该文件存在于 github https://github.com/vuematerial/vue-material

3) 您可能需要按照 github 中的说明进行安装 npm install vue-material@beta --save

在运行之前,请确保执行 npm uninstall vue-material 以删除前一个。

【讨论】:

  • 确认版本是问题所在。使用npm install -s vue-material@beta 是灵丹妙药。如果有人有同样的问题,我会添加更新 npm / 清除 npm 缓存也不会受到伤害。
猜你喜欢
  • 2019-07-03
  • 1970-01-01
  • 2016-06-01
  • 1970-01-01
  • 2015-05-09
  • 2018-10-18
  • 2016-08-12
  • 2019-04-21
  • 2016-12-01
相关资源
最近更新 更多