标签:direct out lin new nbsp vue 注意 创建组 vuerouter
main.js
import Vue from ‘vue‘; import App from ‘./App.vue‘; import VueRouter from ‘vue-router‘; Vue.use(VueRouter); //1.创建组件 import Home from ‘./components/Home.vue‘; import News from ‘./components/News.vue‘; //2.配置路由 注意:名字 const routes = [ { path: ‘/home‘, component: Home }, { path: ‘/news‘, component: News }, { path: ‘*‘, redirect: ‘/home‘ } /*默认跳转路由*/ ] //3.实例化VueRouter 注意:名字 const router = new VueRouter({ routes // (缩写)相当于 routes: routes }) //4、挂载路由 new Vue({ el: ‘#app‘, router, render: h => h(App) }) //5 <router-view></router-view> 放在 App.vue
app.vue
<template> <div id="app"> <router-link to="/home">首页</router-link> <router-link to="/news">新闻</router-link> <hr> <router-view></router-view> </div> </template> <script> export default { data () { return { msg:‘你好vue‘ } } } </script> <style lang="scss"> </style>
标签:direct out lin new nbsp vue 注意 创建组 vuerouter
原文地址:https://www.cnblogs.com/span-phoenix/p/13621559.html