Utilizing tabs in Vue.js to dynamically render distinct components

I've been attempting to utilize a click event on my tabs in order to set the value of a variable within data(). My goal is to then use this variable in an if statement within my components to test the value and display the component if true. However, this approach doesn't seem to be working as expected, and I'm not encountering any errors. I suspect that the variable's value isn't being properly set when the click event on the tabs is triggered. Is it possible that I can't achieve the desired functionality using this method?

<template>
    <div id="settings_page" class="page_body">
        <h1>Settings</h1>

        <div id="user_info" v-if="user">
            <div id="tabs">
                <div v-on:click="selected_tab == 'account'">Account Details</div>
                <div v-on:click="selected_tab == 'divisions'">Divisions</div>
                <div v-on:click="selected_tab == 'users'">Users</div>
                <div v-on:click="selected_tab == 'columns'">Columns</div>
            </div>

            <div class="content">
                <div v-if="selected_tab == 'account'">
                    <h2>Profile</h2>
                </div>

                <div v-if="selected_tab == 'divisions'">
                    divisions
                </div>

                <div v-if="selected_tab == 'users'">
                    users
                </div>

                <div v-if="selected_tab == 'columns'">
                    columns
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import { mapActions, mapGetters } from 'vuex';

    export default {
        data() {
            return {
                selected_tab: 'account'
            }
        },
        computed:mapGetters(['user']),
        methods: {
            ...mapActions(['getProfile'])
        },
        created() {
            this.getProfile();
        }
    }
</script>

Answer №1

Within the click event handler, you are conducting a comparison:

v-on:click="selected_tab == 'account'"

It is recommended to use assignment instead:

v-on:click="selected_tab = 'account'"

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

Code in jQuery or JavaScript to retrieve precise node information for the currently selected form field, text, or image on a webpage

Looking to retrieve specific information about the item that has been clicked on a web page using jquery. The clickable item could be a form element (like a checkbox, text box, or text area) or a section of text within a paragraph, div, list, or image... ...

Tips for preserving the contents of a list with HTML and Javascript

My latest project involves creating a website with a To-Do list feature. Users should be able to add and delete items from the list, which I achieved using JavaScript. Now, my next goal is to ensure that the current items on the list are saved when the pag ...

Using Angular 2 to execute an interface while making an HTTP GET request

I've managed to successfully retrieve and display data from a JSON object using *ngFor in Angular. However, I am struggling with applying an interface to the retrieved data. This is the content of my interface file: import {Offer} from './offer ...

What purpose does the class serve in typescript?

This is a unique version of app.component.ts in the Angular Tour of Hero tutorial. import { Component } from '@angular/core'; export class Superhero{ name : string; id : number; } const SUPERHEROES : Superhero[] = [ {name : 'Wonder ...

Executing a function in a separate component [Angular]

I'm still learning Angular. This question on Stack Overflow is similar to what I'm facing, but it doesn't provide the answer I need. In my case, the two components are independent and not parent-child. They exist at the same directory level, ...

Have you tried switching from Mustache.js to Angular.js and utilizing the triple braces in Angular?

I am currently using Mustache.js with the following setup: <div>{{{icon.tmpl}}}</div> The template icon.tmpl has its own content like this: <div id="{{id}}" class="glyphicon glyphicon-send"></div> When using Mustache.js, both le ...

The react-places-autocomplete feature is causing the components below to be shifted downward

For a while now, I've been facing an issue where using the example provided in the latest README.md GitHub repository is causing the components below to be pushed down, resulting in a less than ideal user experience. To illustrate this problem, I have ...

Having trouble with a basic API Get request?

I'm trying my hand at making a simple get request to fetch a random quote from an API. When I hardcode the change of the quote on button click, everything works smoothly. $(document).ready(function() { $("#quotebtn").on('click', functio ...

Troubleshooting the menu toggle feature in WordPress with jQuery

I am currently working on a Wordpress website that features a sub-menu which I would like to open when a specific 'li' element is clicked, and close upon clicking it again. Despite trying various jQuery functions, I have been unable to achieve th ...

Switching the color of NavLink text when onclick occurs

Is there a way to modify the text color of the links within the navbar using React? navLink1{ color: black; } <div className="left-navlinks"> <img className="logo" src={logo}/> &l ...

Generate a responsive list with a pop-up feature under each item (using Vue.js)

Currently, I believe that Vue may not be necessary since most tasks can be done using JavaScript and CSS. I am attempting to design a list layout as follows: [A] [B] [C] [D] When an item is clicked, the information about that specific item should ...

My AngularJS ng-show functionality is not functioning as expected. I have already reviewed the syntax and still encountering issues

Having trouble with my ng-show, it's not functioning as expected <div class="form-group"> <label class="control-label col-sm-4">NotesTest:</label> <div class="col-sm-4"> <textarea class="form-control ...

Stopping setinterval on click can be achieved by using the clearInterval function in

I've encountered an issue while using a slideshow on my website. The plugin I'm using does not have an autoplay feature, so I had to implement it using setinterval in my code. Below is the code I used: var myInterval, startInt = function(){ ...

Angular: Transferring dynamic functions between parent and grandchild components

For my angular application, I am developing a versatile table component that can accept inputs for rows, columns, as well as handle various action button functions to render the table. The end result should resemble something like this: https://i.sstatic.n ...

What is the process for generating an attribute in a system?

If I want to create an element using plain JavaScript, here is how I can do it: var btn = document.createElement('button'); btn.setAttribute('onClick', 'console.log(\'click\')'); document.body.appendChild( ...

What is the reason for the DOM staying the same, despite the fact that the console shows the correct outcome when attempting to modify link attributes?

function makeLinks(context, url) { var sets = context ? $(context + ' a') : $('a'), prot = url || window.location.protocol; if(prot.match(/https/)){ lockup(sets); } function lockup(elem) { elem.e ...

Enable users to upload and run JavaScript code on the server

Currently, I am diving into the world of javascript/nodeJS with the goal of creating an ERP solution. My aim is to give ERP end-users the ability to upload their own customized scripts which can then interact with existing ERP scripts. It goes without sayi ...

Pass the ActiveRecord object retrieved in the success of the ajax call in Rails as a parameter to another subsequent

Imagine this scenario: I have a view named "Dashboard" featuring a basic form and a button labeled "Draw Graphs". The goal is to trigger two ajax requests upon clicking the button, fetching the required data from the database for creating two distinct grap ...

It is advisable to refrain from directly modifying a prop as the value may be replaced each time the parent component re-renders. Instead of

Need a solution for the issue of mutating a prop directly in Vue.js? You should avoid this because the value will be overwritten whenever the parent component re-renders. Instead, consider using a data or computed property based on the prop's value. T ...

Navigating with Angular and Node: Maximizing the Potential

Currently, I am delving into the world of Node and Angular. As a part of my learning journey, I am in the process of setting up a basic application with three pages. To guide me through this, I have been referring to the documentation provided at: enter li ...