What is the best way to trigger b-tab based on a specific condition?

Hey there, I'm just starting out with Vue3 and I have a bit of a challenge. I've got an SVG image with different parts, a data variable that changes when a particular part of the image is clicked, and some tabs (b-tabs). Is it possible to automatically open a specific tab based on which part of the SVG image is selected?

Below is a snippet of my code:

The SVG image

<rect
   @click="openTab"
   style="fill:#ff0000;stroke-width:0.264583"
   id="limitations"
   width="34.705162"
   height="32.925407"
   x="17.797518"
   y="49.83305" />
        data() {
        return {
            blockClicked: ''
        }
    },

This is my method:

methods: {
        openTab(block) {
            this.blockClicked = block.target.id;
            console.log(this.blockClicked);
        }
    }

I've attempted using :active in the following way but it hasn't been successful:

<b-tabs pills card>
            <b-tab :active="this.blockClicked === 'limitations'">
                <template #title>
                    Limits
                  </template>
            </b-tab>
</b-tabs>

Answer №1

Are you referring to Bootstrap Vue Tabs?

To control the Tabs externally, utilize the v-model attribute (External controls using v-model)

v-model="tabIndex"

Additionally,

<b-button @click="tabIndex = 0">Tab 1</b-button>

Check out this Playground:

Vue.use(BootstrapVue)
new Vue({
  el: '#app',
  data() {
    return { tabIndex: 0 }
  }
})
#app { line-height: 2; }
[v-cloak] { display: none; }
label { margin-left: 8px; }
<!-- Load required Bootstrap and BootstrapVue CSS -->
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />

<!-- Load Vue followed by BootstrapVue -->
<script src="https://unpkg.com/vue@^2/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>

<div id="app">
  <b-tabs pills card v-model="tabIndex">  
      <b-tab title="First" active>
        First
      </b-tab>  
      <b-tab title="Second">      
        Second
      </b-tab>  
      <b-tab title="Third">
        Third
      </b-tab>  
  </b-tabs>  
  <hr/>
   <b>tabIndex:</b> {{tabIndex}}<br/>
    <b-button variant="outline-primary" size="sm" @click="tabIndex = 0">Tab 1</b-button>
    <b-button variant="outline-primary" size="sm" @click="tabIndex = 1">Tab 2</b-button>
    <b-button variant="outline-primary" size="sm" @click="tabIndex = 2">Tab 3</b-button>
</div>

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

Guide on utilizing the reduce method with objects

I am attempting to use the reduce method on an object to create an HTML list const dropdownTemplate = (data) => { console.log(data); // no data displayed return ` <li class="dropdown__item" data-value="${data.value}"><span class="dropdown__i ...

Refreshing ng-model within a radio input

Currently, I am utilizing a jQuery library for radio/checkbox components. Although I am aware that combining jQuery with Angular is not ideal, the decision to use this particular library was out of my control and cannot be altered. One issue I have encount ...

JavaScript regular expressions: filtering out results from the output

I'm trying to extract a specific number from a dynamically added string. The text looks like this: nisi non text600 elit, where 600 is the number I need to retrieve. Is there a way to achieve this without replacing the word text? var str = ('nis ...

Can anyone provide guidance on how to calculate the total sum of a JavaScript array within an asynchronous function?

Currently, I am working with Angularjs Protractor for end-to-end testing and faced an issue while trying to calculate the sum of values in a column. Although I am able to print out each value within the loop successfully, I am struggling to figure out ho ...

Arranging Vue numbers

Vue data contains: data: { offices: requestData, selectedFloors: [ "3", "4", "5", "10", "11", "12", ...

RouterContext Error: Invariant violation: Do not utilize <withRouter(App) /> in a context without a <Router> present

After wrapping my app with BrowserRouter and trying to export it as withRouter(App), I encountered the following error in the browser: 16 | return ( 17 | <RouterContext.Consumer> 18 | {context => { > 19 | invariant( | ^ ...

The script for tracking cursor coordinates is incompatible with other JavaScript code

<html> <script language="javascript"> document.onmousemove=function(evt) { evt = (evt || event); document.getElementById('x').value = evt.clientX; document.getElementById('y').value = evt.clientY; document.ge ...

What is the best way to pass the "$user" variable in a loadable file using ajax?

Is there a way to send the variable user to the mLoad.php file before executing this script? Any suggestions would be greatly appreciated. Thank you! $(document).ready(function(){ $("#message_area").load('mLoad.php'); $("#userArea").submit(func ...

What is the best way to configure my AngularJS routing for managing URL rewriting and page reloads effectively?

As I develop my website using AngularJS, one of my main goals is to create a smooth navigation experience without the annoying "browser flash" effect that occurs when switching between pages. This means that clicking on a link in index.html to go to foo.ht ...

Tips for keeping a reading item in place while scrolling

To enhance the user experience, I would like to improve readability without affecting the scroll position. Question: Is there a way to fix the scrolling item at a specific position (item with the .active class)? I am looking to maintain a consistent read ...

What is the procedure for employing suitscript within Restlet in the NetSuite environment?

Currently, I am working on creating a restlet in Netsuite to retrieve details about a specific Field. The code snippet I have been using is as follows: error code: UNEXPECTED_ERROR error message:TypeError: Cannot call method "getType" of null (login.js$12 ...

Node.js is throwing an error "Unexpected token v in JSON at position 0" which

I'm currently working on developing PHP code within the Google App Engine flexible environment. Specifically, I am facing some challenges in setting up the Firebase SDK Admin for the web version. My main struggle lies with the following block of code ...

I made a mistake with my git repository. Should I try to fix it or just start fresh?

After spending months learning web development, I recently completed my first project. Unfortunately, right before deployment, I made a mistake with my backend git tree. I attempted to resolve the issue using suggestions from other resources, but none of ...

Learn how to easily set a radio button using Angular 4 and JavaScript

It seems like a simple task, but I am looking for a solution without using jQuery. I have the Id of a specific radio button control that I need to set. I tried the following code: let radiobutton = document.getElementById("Standard"); radiobutton.checke ...

JavaScript Regular Expression for separating a collection of email addresses into individual parts

I am very close to getting this to work, but not quite there yet. In my JavaScript code, I have a string with a list of email addresses, each formatted differently: var emailList = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data- ...

Tips for utilizing the "this" keyword in JavaScript

Here's a snippet of code that I'm having trouble with: this.json.each(function(obj, index) { var li = new Element('li'); var a = new Element('a', { 'href': '#', 'rel': obj ...

Guide to displaying a partial in the controller following an ajax request

After initiating an AJAX request to a method in my controller, I am attempting to display a partial. Below is the AJAX call I am currently using: $('.savings_link').click(function(event){ $.ajax({ type: 'GET', url: '/topi ...

Tips for designing a sophisticated "tag addition" feature

Currently, I am enhancing my website's news system and want to incorporate tags. My goal is to allow users to submit tags that will be added to an array (hidden field) within the form. I aim to add tags individually so they can all be included in the ...

Loading views and controllers on-the-fly in AngularJS

A new configuration tool is under development using Angular.JS. The user interface consists of two main sections: a left panel with a tree view listing all the configuration items and a right panel displaying screens for editing these items. There are appr ...

Displaying a page using express.Router()

I'm having trouble figuring out how to incorporate EJS rendering into a file utilizing express.Router(). The usual method of router.set('view engine', 'ejs') doesn't seem applicable in this context. Any ideas on how I can succ ...