使用 vue-router 获取 URL 查询参数

发布时间: 2018-09-05 19:27:30 作者: 大象笔记

引入 vue-router.min.js,然后与 Vue 实例绑定即可

例如: http://www.sunzhongwei.com/test_vue?name=zhongwei

var router = new VueRouter({
    mode: 'history',
    routes: []
});

new Vue({
    router,
    el: '#my_app',
    mounted: function() {
        var name = this.$route.query.name;
	console.log(name);
    },
});
我是一名山东烟台的开发者,联系作者