(Vue.js) Same component with different routes

后端 未结 3 1161
别跟我提以往
别跟我提以往 2020-12-16 12:53

I would like to use the same component for different routes in a Vue.js application.

I currently have something like this:


main.js

3条回答
  •  囚心锁ツ
    2020-12-16 13:24

    Just to make a note. If anybody is working with SSR template, things are a bit different. @mzgajner's answer does indeed recreate the component but will not trigger the asyncData again.

    For that to happen, modify entry-client.js like this.

    OLD:

    const activated = matched.filter((c, i) => {
        return diffed || (diffed = (prevMatched[i] !== c))
    })
    

    NEW:

    const activated = matched.filter((c, i) => {
    
        /*
            In my case I only needed this for 1 component
        */
    
        diffed = ((prevMatched[i] !== c) || c.name == 'p-page-property-map')
    
        return diffed
    })
    

提交回复
热议问题