zoukankan      html  css  js  c++  java
  • vue-router基本使用

    import Vue from 'vue'
    import VueRouter from 'vue-router'

    Vue.use(VueRouter)

    const First = { template: '<div>First</div>' }
    const Second = { template: '<div>Second</div>' }
    const Home = { template: '<div>Home</div>' }

    const OtherFirst = {
    template: `
    <div class="asdf">
    <h2>包含子视图</h2>
    <router-view class="asdf-routerview"></router-view>
    </div>
    `
    }
    const One = { template: '<div>First-One</div>' }
    const Two = { template: '<div>First-Two 此处有路由里面的query参数:{{ $route.query.id }}</div>' }
    const Three = { template: '<div>First-Three 此处有路由里面的params参数:{{ $route.params.id }}</div>' }

    const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [
    { path: '/', name:'home', component: Home },
    { path: '/onlyfirst', name:'onlyfirst', component: First },
    { path: '/firsthaschild', component: OtherFirst,
    children: [
    { path: '/', name:'child-default', component: One },
    { path: 'one', name:'child-one', component: One },
    { path: 'two', name:'child-two', component: Two },
    { path: 'three', name:'child-three', component: Three },
    ]
    },
    { path: '/second', name:'second', component: Second },
    ]
    })


    new Vue({
    router,
    template: `
    <div id="r">
    <h1>导航</h1>
    <ul>
    <li><router-link to="/">/home</router-link></li>
    <li><router-link to="/onlyfirst">only first</router-link></li>
    <li><router-link to="/firsthaschild">first has child</router-link></li>
    <ul>
    <li><router-link to="/firsthaschild/one">first-one</router-link></li>
    <li><router-link :to="{ path:'/firsthaschild/two', query: { id: 'query-id' } }">first-two</router-link></li>
    <li><router-link :to='{ name: "child-three", params:{ id: "params-id" } }'>first-three</router-link></li>
    </ul>
    <li><router-link to="/second">second</router-link></li>
    </ul>
    <router-view class="routerview"></router-view>
    </div>
    `
    }).$mount("#app")
  • 相关阅读:
    Robot Framework-资源文件的使用方法(7)
    Robot Framework-用户关键字的使用方法(6)
    robotframework 新建UI自动化测试用例实例一(2)
    robotframework--登录接口,post传递多个参数、及获取content中指定属性的值(5)
    robotframework基础知识(2)
    win7如何打开防火墙某个端口的tcp连接
    外观模式
    享元模式
    代理模式
    模板模式
  • 原文地址:https://www.cnblogs.com/wpw1215/p/10594869.html
Copyright © 2011-2022 走看看