What is the best way to add a separator in a b-dropdown menu once the options have been loaded using Vue?

Here is the code snippet for my dropdown element:

<b-dropdown id="SchemaDropdown"
                      name="SchemaDropdown"
                      variant="form-control"
                      class="" 
                      style="width: 100%"
                      v-on:change="changeItem">
                      <span slot=text>{{schemaName}}</span>
                    <b-dropdown-item v-for="option in schemas.Formats" 
                                      :key="option.mappingId" 
                                      :value="option.mapping"
                                      @click="changeItem(option.mappingId)">
                      {{option.mapping}}
                    </b-dropdown-item>
                    <b-dropdown-divider></b-dropdown-divider>
                  </b-dropdown> 

The schemas object contains available schemas and their corresponding GUIDs. The dropdown functions correctly, selecting schemas as intended.

In the system, the first two schemas are default while the rest are customizable based on user settings. Some users may have only a few custom schemas, while others may have many.

I would like to add a divider after the second default schema to structure the dropdown like this:

Default Schema 1
Default Schema 2
----------------
User Configured 1
User Configured 2
etc...

How can I insert the `b-dropdown-divider` at a specific position in the dropdown?

Answer №1

If you're looking to achieve this, computed properties are your solution:

  <b-dropdown-item 
      v-for="option in defaultOptions" 
     :key="option.mappingId" 
     :value="option.mapping"
     @click="changeItem(option.mappingId)">
     {{option.mapping}}
    </b-dropdown-item>

    <b-dropdown-divider></b-dropdown-divider>

    <b-dropdown-item 
      v-for="option in customOptions" 
     :key="option.mappingId" 
     :value="option.mapping"
     @click="changeItem(option.mappingId)">
     {{option.mapping}}
    </b-dropdown-item>

To implement in JavaScript:

    computed: {
      defaultOptions: function () {
        return this.schemas.Formats.slice(0, 2)
      },
      customOptions: function () {
        return this.schemas.Formats.slice(2, this.schemas.Formats.length)
      }
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it just me or does my node server come preconfigured with CORS enabled? What am I overlooking here?

I have a simple node and express server set up here. Surprisingly, even without any middleware, I am able to successfully log the response from an axios request made to google.com. Doesn't this usually trigger a cors error, requiring some form of midd ...

Is your angularjs localstorage giving you trouble?

I am encountering an issue with local storage on my webpage. Upon initial visit, I am seeing an outdated value from local storage. However, upon refreshing the page, I am able to access the current value. How can I prevent this error and ensure that I only ...

vue.js and the various elements that make up its architecture

My component content is not appearing!!! I have checked the router multiple times and it seems to be functioning correctly, but when I run the project, the components are empty. Even though I have added a lot of content to them, they appear to be blank. ...

Issue with Vue and Firebase: New users are being created successfully, but are being logged into existing user accounts

I've encountered a strange issue in Firebase. When I create a new user with the same password as an existing user, the new user is logged in under the previous user's account and displays all their information. However, upon logging out and signi ...

A helpful guide on displaying validation errors in a form using React JS

After creating a form and connecting it to the server, I encountered an issue with displaying validation errors below respective input fields. The error message response in case of validation error is as follows: "message": "ValidationError: confirmPasswor ...

Encountered an unfamiliar custom element: x while utilizing Buefy

Following the Buefy guidelines, I took the necessary steps. First, I ran: npm install Buefy Next, in my main.ts file, I imported Vue, Buefy, axios, and VueAxios like so: import Vue from 'vue'; import Buefy from 'buefy'; import axio ...

The TextBox will alter its color following an incorrect submission

I am struggling to create a bootstrap form that will change the color of the borders to red after incorrect submission. The issue I am facing is that the textbox always remains in red. Does anyone have any suggestions for setting the textbox borders to red ...

Vue component does not inherit scoped CSS

One issue I encountered involves a scoped style tag in my Vue component: <style scoped> .ttt{ background-color: red; } </style> After building the project with npm and webpack, the styles were not being copied over. To address ...

Running both the React FrontEnd and NodeJs Backend on a single server

I have developed a full-stack application using React for the frontend and server.js written in nodejs(Express), with Postgres as my database backend. I have previously deployed a similar setup on Heroku, where I hosted my site. The difference is that on H ...

Is it possible in Vue.js to create a reactive functionality for a button using a watcher for "v-if" condition?

I have a userlist page with various profiles, including my own. A button is supposed to appear only when viewing my own profile. The issue arises when switching from a different profile to my own (changing the router parameter) - the button should show up ...

Colorful D3.js heatmap display

Hello, I am currently working on incorporating a color scale into my heat map using the d3.schemeRdYlBu color scheme. However, I am facing challenges in getting it to work properly as it only displays black at the moment. While I have also implemented a ...

Issue encountered when attempting to push jQuery AJAX requests into an array

I'm attempting to store ajax requests in an array called deferreds. However, I'm consistently encountering the error message below: Uncaught SyntaxError: missing ) after argument list As a reference, I've been using this guide: Pass in an ...

Form fields in Bootstrap 4 will consistently expand downward in the select dropdown menu

When using bootstrap 4, I want my field to always expand downwards and never upwards, even when half the screen is taken up by the form's select element. How can I achieve this effect? I have tried using data-dropup-auto="false" but it didn't wo ...

Obtain the value stored in the variable named "data"

I'm trying to calculate the sum of data values using jQuery, similar to this example: { label: "Beginner", data: 2}, { label: "Advanced", data: 12}, { label: "Expert", data: 22}, and then add them together. Like so: var sum = data1+data2+dat ...

Ways to expand CRA ESLint guidelines using the EXTEND_ESLINT environmental variable

Facebook's Create React App (CRA) recently introduced a new feature allowing users to customize the base ESLint rules. Recognizing that some cases may require further customization, it is now possible to extend the base ESLint config by setting the ...

Using node modules within an HTML document

I'm finding it challenging to understand how npm handles dependencies when it comes to referencing them in HTML. For example, if I have a specific version of a plugin installed that includes the version number in its path or file name, and npm is set ...

Displaying Image Previews in Rails View Using JavaScript

I am working on a functionality where I have a text_field that contains the URL of an image. The goal is to load this URL into an img tag and update the preview image when the user changes the URL in the text field. Below is the relevant erb code for the ...

Error encountered while making a REST API call in Ajax: Unforeseen SyntaxError: Colon unexpected

I am currently troubleshooting my code to interact with a REST API. My platform of choice is "EspoCRM" and I aim to utilize its API functionalities. The official documentation recommends using Basic Authentication in this format: "Authorization: Basic " ...

Issue with Mongoose's deep population feature not functioning as expected

I'm currently working on a web application that requires the use of mongoose-deep-populate. I've already installed it using npm, but unfortunately, I keep encountering the following error: Error: Plugin was not installed at Query.deepPopulate (/ ...

Does implementing a product listing with filter, sorting, and search options through Ajax violate any REST principles?

As I work on creating a product listing library for a web application, it's crucial to incorporate filter, search, and sort functionalities. A web service is available that can fetch results based on these parameters, including page number and product ...