how to make bootstrap4 collapse work in vue?

前端 未结 3 978
长发绾君心
长发绾君心 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:48

      This is the implementation of no jquery

      new Vue({
        el: '#app',
        data() {
          return {
            menuList: [{
                name: 'Products',
                expand: false,
                items: [{
                    name: 'Item List 1',
                    link: ''
                  },
                  {
                    name: 'Item List 2',
                    link: ''
                  }
                ]
              },
              {
                name: 'Others',
                expand: false,
                items: [{
                    name: 'Other Item 1',
                    link: ''
                  },
                  {
                    name: 'Other Item 2',
                    link: ''
                  }
                ]
              }
            ]
          }
        },
        methods: {
          navItemCollapse(index) {
            this.menuList = this.menuList.map((item, i) => {
              item.expand = !item.expand
              if (i !== index) {
                item.expand = false
              }
              return item
            })
          }
        }
      })
      
      
      
      

      I integrate the menu data into an array of objects. Each object has an expand flag to determine whether it is currently expanded. When you click on the menu, switch the expand flag of the current menu.

      Note: You don't need to care about the id of the tag.

    提交回复
    热议问题