vue-material:未知的自定义组件md-drawer& MD-内容

时间:2017-11-29 03:45:13

标签: javascript vue.js vuejs2 vue-material

尝试呈现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.

<md-content>组件有相同的错误消息。

这是代码。

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>

main.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 in generald的事情!

1 个答案:

答案 0 :(得分:2)

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以删除上一个。