鍍金池/ 問(wèn)答/HTML/ vue組件不顯示

vue組件不顯示

模仿慕課網(wǎng)教程里的移動(dòng)端音樂(lè)app,為什么run dev后不顯示組件呢。請(qǐng)各位幫忙看看。

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
    }
  ]
})

其中一個(gè)組件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>

頁(yè)面只顯示黑色背景,看源碼發(fā)現(xiàn)組件都沒(méi)掛載上,只有一個(gè)空的html頁(yè)面。

回答
編輯回答
哎呦喂

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')
    }
  },

然后重啟服務(wù) npm run dev

2018年6月20日 09:08
編輯回答
忠妾

引入組件的路徑不正確

2017年5月20日 09:47