跟着視頻敲代碼發現路由標籤 <router-view></router-view>就是不渲染
import Vue from 'vue'
import VueRouter from 'vue-router'
const Home = ()=> import('../views/home/Home.vue')
const Category = ()=> import('../views/category/Category')
const Cart = ()=> import('../views/cart/Car')
const Profile = ()=> import('../views/profile/Profile')
//安裝插件
Vue.use(VueRouter)
//創建路由
const routers=[
{
path:'',
redirect:'/home'
},
{
path:'/home',
component:Home
},
{
path:'/category',
component:Category
},
{
path:'/cart',
component:Cart
},
{
path:'/profile',
component:Profile
},
]
const router = new VueRouter({
//問題在這裏
routers,
mode:'history'
})
//導出路由
export default router
解決方法
const router = new VueRouter({
routes,//routes是一種簡寫方式 等同於 routes:routers,
mode:'history'
})
//vue 默認的單詞是routes 所以如果你定義的變量名字和routes不一致就不能簡寫