vue 路由 URL传参

源码如下:

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

Vue.use(VueRouter) //全局使用该组件

const router = new VueRouter({
    mode:'history',
    base:__dirname,
    routes:[
        {
            path:'/'
        },
        {
            path:'/params/:aaa/:bbb' //绑定模板
        }
    ]
})

new Vue({
    router,
    template:`
        <div>
            <h1>Good Morning</h1>
            <ul>
                <li><router-link to="/">/</router-link></li>
                <li><router-link to="/params/111/222">/params/111/222</router-link></li>
            </ul>
            <p>show</p>
            <pre>
                <code>
                    {{$route.params.bbb}}
                    {{JSON.stringify($route,null,2)}}
                </code>
            </pre>
        </div>
    `
}).$mount('#app')

猜你喜欢

转载自www.cnblogs.com/candy-Yao/p/9365726.html