how to make bootstrap4 collapse work in vue?

前端 未结 3 980
长发绾君心
长发绾君心 2021-01-27 18:19

I am using bootstrap 4.3.1 and vue@2.6.10

I have this menu (is using collapse - and I don`t want to use JQuery):

 
  • <
  • 3条回答
    •  逝去的感伤
      2021-01-27 18:42

      I like the @sugars approach :)

      So...the final version is this:

      
      

      the sidenavItems:

       sidenavItems: [
                          {name: 'Dashboard', isCollapsible: false, route: 'dashboard', class: 'class1'},
                          {name: 'Categories', isCollapsible: false, route: 'category', class: 'class2'},
                          {name: 'Brands', isCollapsible: false, route: 'brand', class: 'class3'},
                          {name: 'Products', isCollapsible: true, expanded: false, class: 'class4', items: [{name: 'List', route: 'product'}]},
                          {name: 'Orders', isCollapsible: false, route: 'order', class: 'class5'},
                          {name: 'Blog', isCollapsible: true, expanded: false, class: 'class6', items: [{name: 'List', route: ''}]},
                      ],
      

      and the navItemCollapse method:

       navItemCollapse(index) {
           this.sidenavItems = this.sidenavItems.map( (item, i) => {
                      item.expanded = !item.expanded;
                      if(i !== index) {
                          item.expanded = false;
                      }
                      return item;
                  })
              }
      
      

    提交回复
    热议问题