简体   繁体   中英

How to pass props from URL in vueJS when redirect in vue router?

My '/' path redirect to '/loading' and I need to pass props like mysite/?demo=true and then that prop pass to the component attached to '/loading'

this is the router config

{
  path: '/',
  redirect: '/loading',
},
{
  path: '/loading',
  component: Loading
},

Do:

    {
      path: '/',
      redirect: { path: '/loading', params: { default: true, demo: true } }
    },
    {
      path: '/loading',
      component: Loading
    },

And in your Loading component, you define a prop called demo, like:

props: {
  demo: Boolean,
}

Then you will be able to access this.demo and read true, wich is the value passed via route.

在Mathew的解决方案的基础上,访问route参数,您可以执行this.$route.params.demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM