您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

vue-router的使用详解

2024/3/12 14:22:31发布37次查看
这次给大家带来vue-router的使用详解,vue-router使用的注意事项有哪些,下面就是实战案例,一起来看一下。
<!doctype html><html lang="en"> <head>   <meta charset="utf-8" />   <title> vue route demo</title> </head> <body> <script src="https://unpkg.com/vue/dist/vue.js"></script> <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script> <p id="app">  <h1>hello app!</h1>  <p>   <!-- 使用 router-link 组件来导航. -->   <!-- 通过传入 `to` 属性指定链接. -->   <!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->   <router-link to="/foo">go to foo</router-link>   <router-link to="/bar">go to bar</router-link>  </p>  <!-- 路由出口 -->  <!-- 路由匹配到的组件将渲染在这里 -->  <router-view></router-view> </p> <script> // 0. 如果使用模块化机制编程,導入vue和vuerouter,要调用 vue.use(vuerouter) // 1. 定义(路由)组件。 // 可以从其他文件 import 进来 const foo = { template: '<p>foo</p>' } const bar = { template: '<p>bar</p>' } // 2. 定义路由 // 每个路由应该映射一个组件。 其中component 可以是 // 通过 vue.extend() 创建的组件构造器, // 或者,只是一个组件配置对象。 // 我们晚点再讨论嵌套路由。 const routes = [  { path: '/foo', component: foo },  { path: '/bar', component: bar } ] // 3. 创建 router 实例,然后传 `routes` 配置 // 你还可以传别的配置参数, 不过先这么简单着吧。 const router = new vuerouter({  routes // (缩写)相当于 routes: routes }) // 4. 创建和挂载根实例。 // 记得要通过 router 配置参数注入路由, // 从而让整个应用都有路由功能 const app = new vue({  router }).$mount('#app') // 现在,应用已经启动了! </script> </body> </html>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
使用js实现表单验证(附代码)
ajax与jsonp的使用详解
vue.js渐进式框架使用详解
以上就是vue-router的使用详解的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product