How to pass an object as props with vue router?

后端 未结 1 1152
遇见更好的自我
遇见更好的自我 2020-12-05 10:28

I have the following fiddle https://jsfiddle.net/91vLms06/1/

const CreateComponent = Vue.component(\'create\', {
  props: [\'user\', \'otherProp\'],
  templa         


        
相关标签:
1条回答
  • 2020-12-05 11:07

    It can work by using props's Function mode and params

    demo: https://jsfiddle.net/jacobgoh101/mo57f0ny/1/

    when adding routes, use props's Function mode so that it has a default property user and it will add route.params as props.

    {
        path: '/create',
        name: 'create',
        component: CreateComponent,
        props: (route) => ({
            user: userData,
            ...route.params
        })
    }
    

    params passed in push will automatically be added to props.

    self.$router.push({
        name: 'create',
        params: {
            otherProp: {
                "a": "b"
            }
        }
    })
    
    0 讨论(0)
提交回复
热议问题