How to realize dynamic tab components with vue?

description: mobile web uses vue to implement the left and right column layout. The left side is a list of various information table names, and the right side is the content that is loaded dynamically after clicking the left menu. The content on the right is mainly a variety of forms, and there are default values (users can modify and submit).

implementation method:
idea 1. The list on the left and the content on the right are different components, such as left.vue right.vue, which consists of two single files.
idea 2. The list on the left and the content on the right are inside the same component. The switching of content is achieved by dynamic component switching.

which implementation is better? Personally, I think the second kind is better and more holistic!

added: passing values between sibling components, that is, updating different forms of the right component according to the different items clicked on the left menu, is it better to use event bus than vuex? when the project is small?


I agree with the first one. The second although you think the integrity is strong, but if all soft into a component, the code will be very messy, very much, very bad for future maintenance and modification.

< hr >

Yes, event notification is a little more convenient than vuex when you don't have a lot of components and data involved.


I will write in a component, on the left is a tab, on the right is a dynamic component,

<template>
    <div class="tabs">
        <tab-item
            v-for="tab in tabs"
            @click.native="onTabClick(tab)">
    </div>
    <components :is="currentTab.component">
</template>

<script>
export default {
    data() {
        return {
            tabs: [
                {
                    name: 'a',
                    component: 'cpA'
                }            
            ],
            currentTab: {
                name: 'a',
                component: 'cpA'
            }
        }
    },
    methods: {
        onTabClick(tab) {
            this.currentTab = tab
        }
    }
}
</script>

I simply do it for you, and that's about it.


if I do it, I still have to do it according to whether the content on the right is uniform, such as takeout, different categories, and different products on the right, then it must be the same component.
in your case, there are mainly different forms on the right, even more if the contents of the forms are different. Certainly tend to different components, and can even use different routes, two-level routing to do

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bbbcd1-302b8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bbbcd1-302b8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?