vue3.0 vue-router的使用
refer: https://v3.router.vuejs.org/installation.html#direct-download-cdn
1.安装依赖:
npm install vue-router
2.创建router.js,使用vue-router
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)例如:
<span style="color:#dcc6e0">import</span> Vue <span style="color:#dcc6e0">from</span> <span style="color:#abe338">'vue'</span>;
<span style="color:#dcc6e0">import</span> VueRouter <span style="color:#dcc6e0">from</span> <span style="color:#abe338">'vue-router'</span>;
<span style="color:#dcc6e0">import</span> HelloWorld <span style="color:#dcc6e0">from</span> <span style="color:#abe338">'./components/HelloWorld.vue'</span>;
Vue.use(VueRouter);
export <span style="color:#dcc6e0">default</span> <span style="color:#f5ab35">new</span> Router({
routes: [
{
<span style="color:#f5ab35">path</span>: <span style="color:#abe338">'/hello_world'</span>,
<span style="color:#f5ab35">name</span>: <span style="color:#abe338">'HelloWorld'</span>,
component: HelloWorld
},
]
});此时,打开http://localhost:8081/hello_world就可以看到页面了: