美文网首页
Vue Router Demo

Vue Router Demo

作者: wjundong | 来源:发表于2021-09-04 18:22 被阅读0次
  • index.html
<!DOCTYPE html>

<html>

<head>

</head>

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

        <button @click="go_bar">go bar</button>
        <button @click="go_foo">go foo</button>

        <!-- 显示路由后的视图 -->
        <router-view> </router-view>
        
    </div>

    <script>
        // 定义组件
        const Foo = { template: '<div>foo</div>' }
        const Bar = { template: '<div>bar</div>' }

        // 定义路由
        const routes = [
            { path: '/foo', component: Foo },
            { path: '/bar', component: Bar }
        ]

        // 创建 router 实例,然后传 `routes` 配置
        const router = new VueRouter({
            routes: routes
        })

        // 创建和挂载根实例
        const app = new Vue({
            router,
            methods: {
                go_bar : function() {
                    this.$router.push('/bar')
                },
                go_foo : function() {
                    this.$router.push('/foo')
                },
            }
        }).$mount('#app')

    </script>
</body>

</html>

相关文章

  • vue-router配置

    祭出demo: vue-router配置demo 这篇文章介绍的vue-router配置是基于vue-cli脚手架...

  • Vue Router Demo

    index.html

  • vue-router踩了一个坑

    最近一直在学vue,今天用新学a的vue-router做了一个小demo,结果里的内容硬...

  • 2019-04-01

    Vue.js工程化项目起步——vue-router-demo: 本例主要采用vue-cli配合webpack来创建...

  • Vue脚手架程序构建

    1、进入某个目录 2、通过命令创建项目:vue init webpack vue-router-demo1(后几项...

  • 2 Vue.js工程化项目起步

    1.vue-router-demo 后端:1.一级路由demovue-router-demol(脚手架)2.把相应...

  • code1 Vue-Router

    一. 通过Vue CLI 快速创建一个项目 vue create router-demo1 在终端中执行指令 ...

  • SPA:单页应用

    1.一级路由 demo 脚手架:vue-router-demo 2.把相应的API实现 3.前后联调 一个Vue的...

  • vue2实现移动端开发

    基于vue2+webpack+vue-router+vuex开发的适用移动端的h5 app demo,包含路由的处...

  • 笔记1

    1、SPA:单页应用 2、 一级路由demo 脚手架:vue-router-demo1 写样式 把相应的API...

网友评论

      本文标题:Vue Router Demo

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