根据路由参数 vuejs 加载组件/模板 [英] Load component/template depending on the route param vuejs

查看:46
本文介绍了根据路由参数 vuejs 加载组件/模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下我是否可以在 vuejs 上实现这个,所以基本上代码会根据 param url 加载一个页面/模板.我已经搜索了一段时间,但没有得到我需要的结果,或者我可能只是搜索了错误的关键字.

I would like to ask if can I implement this on vuejs, so basically the code will load a page/template base on the param url. I've been searching for a while and can't get the results I need or maybe I'm just searching a wrong keyword.

我的网址是这样的,所以我不能在我的路线中手动声明网址,因为它是动态的,从数据库中获取.

My url is like this, so I just can't manually declare the url in my route because it is dynamic, fetch from the database.

path: '/user/page_type

非常感谢!

export default {
    mounted () {
        if(this.$routes.params.page_type == "home"){
            // Load Homepage Here
            // ../../../page/HomePage.vue
        }
        else if(this.$routes.params.page_type == "speaker"){
            // Load Speakerpage Here
            // ../../../page/HomePage.vue
        }
        else if(this.$routes.params.page_type == 'html'){
            // Load HTML Page Here
            // ../../../page/HtmlPage.vue
        }
    }
}

推荐答案

这是在官方插件 vue-router 中开箱即用的.

This is available out of the box within official addon vue-router.

您的案例文档:link

这篇关于根据路由参数 vuejs 加载组件/模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆