vue-router 中router-view不能渲染的解決方案,vuerouter不渲染

來源:互聯網
上載者:User

vue-router 中router-view不能渲染的解決方案,vuerouter不渲染

最近在做一個vue的項目,其中使用了vue2.0,vue-router2.0。在使用vue-router的時候跳了一個很大的坑,router-view不能渲染,花費了好多時間終於發現了原因。

項目目錄結構

其中main.js

import Vue from 'vue';import App from './App';import router from './router';/* eslint-disable no-new */new Vue({ el: '#app', router, render: h => h(App)});

app.vue

<template> <div id="app">   <div class="tab">    <div class="tab-item">     <router-link to="/goods">商品</router-link>    </div>    <div class="tab-item">     <router-link to="/ratings">評論</router-link>    </div>    <div class="tab-item">     <router-link to="/seller">商家</router-link>    </div>   </div>   <div>    <router-view></router-view>   </div> </div></template><script> export default {  name: 'app',  components: {  } };</script><style lang="stylus" rel="stylesheet/stylus"> .tab  display: flex  width: 100%  height: 40px  line-height: 40px  .tab-item   flex: 1   text-align: center   & > a    display: block</style>

router/index.js

import Vue from 'vue';import VueRouter from 'vue-router';import goods from '../components/goods/goods.vue';import ratings from '../components/ratings/ratings.vue';import seller from '../components/seller/seller.vue';Vue.use(VueRouter);const routes = [ { path: '/goods', component: goods }, { path: '/ratings', component: ratings }, { path: '/seller', component: seller }, { path: '*', redirect: '/goods' }];const router = new VueRouter({ routes: routes   //注意是routes而不是routers,坑就在這裡});export default router;

其中在index.js中使用了各種方法,最後查看文檔發現原來是routes惹的禍,每次都寫的是routers,導致路由根本就沒有匯入進去,所以在渲染的時候一直不能顯示content。如下官方文檔中的例子:

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.