美文网首页
vue-router.html

vue-router.html

作者: harry_海瑞 | 来源:发表于2018-12-29 11:31 被阅读0次

    <!DOCTYPE html>

    <html lang="en">

    <head>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <meta http-equiv="X-UA-Compatible" content="ie=edge">

        <title>Document</title>

    </head>

    <body>

    </body>

    <script src="https://unpkg.com/vue/dist/vue.js"></script>

    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>

    <div 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>

    </div>

    <script>

    // 1. 定义(路由)组件。

    // 可以从其他文件 import 进来

    const Foo = { template: '<div>foo</div>' }

    const Bar = { template: '<div>bar</div>' }

    // 2. 定义路由

    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>

    </html>

    相关文章

      网友评论

          本文标题:vue-router.html

          本文链接:https://www.haomeiwen.com/subject/eqyulqtx.html