vue组件不显示

模仿慕课网教程里的移动端音乐app,为什么run dev后不显示组件呢。请各位帮忙看看。

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=0,maximum-scale=1.0
    minimum-scale=1.0,userscalable=no">
    <title>vue-music</title>
  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

app.vue

<template>
  <div id="app">
    <m-header></m-header>
    <tab></tab>
    <router-view></router-view>
    <hello></hello>
  </div>
</template>

<script type="text/ecmascript-6">
  import MHeader from 'components/m-header/m-header'
  import Tab from 'components/tab/tab'
  import Hello from 'components/hello/hello'

  export default {
    name: 'app',
    components: {
      MHeader,
      Tab,
      Hello
    }
  }
</script>

<style scoped lang ="stylus" rel="stylesheet/stylus">

</style>

main.js

import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import fastclick from 'fastclick'
import 'common/stylus/index.styl'
import router from './router'

fastclick.attachEvent(document.body)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})

router/index.js

import Vue from 'vue'
import Router from 'vue-router'
import Recommend from 'components/recommend/recommend'
import Rank from 'components/rank/rank'
import Search from 'components/search/search'
import Singer from 'components/singer/singer'

Vue.use(Router)

export default new Router({
  routes: [

    {
      path: '/',
      redirect: Recommend
    },
    {
      path: '/recommend',
      component: Recommend
    },
    {
      path: '/rank',
      component: Rank
    },
    {
      path: '/singer',
      component: Singer
    },
    {
      path: '/search',
      component: Search
    }
  ]
})

其中一个组件components/m-header.vue

<template>
  <div class="m-header">
    <div class="icon">
      <h1 class="text">william music</h1>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {}
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  @import "~common/stylus/variable.styl"
  @import "~common/stylus/mixin.styl"

  .m-header
    position:relative
    height:40px
    text-align:center
    color: $color-theme
    font-size :0
    .icon
      display :inline-block
      vertical-align :top
      margin-top : 6px
      width : 30px
      height :32px
      margin-right :9px
      bg-image('logo')
      background-size :30px 32px
    .text
      display :inline-block
      vertical-align :top
      line-height :44px
      font-size: $font-size-large
    .mine
      position: absolute
      top: 0
      right: 0
      .icon-mine
        display: block
        padding: 12px
        font-size: 20px
        color: $color-theme
</style>

页面只显示黑色背景,看源码发现组件都没挂载上,只有一个空的html页面。

阅读 3.9k
2 个回答

引入组件的路径不正确

webpack.base.conf.js里面添加alias别名支持了么?

'components':resolve('src/components')

如下:

resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
      'components':resolve('src/components')
    }
  },

然后重启服务 npm run dev

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题