Utilizing Vue.js for Tabs in Laravel 5.8

I am encountering an issue in Laravel while attempting to set up a Vue instance for tabs. Currently, only Tab 1 and Tab 2 are displayed without any content, and the tabs themselves are not clickable links.

Could this problem be related to how I am calling Vue? Interestingly, I have Vue natively installed on Laravel 5.8 and it is functioning properly elsewhere.

<div id="tabs" class="container">
<div class="tabs">
    <a v-on:click="activetab=1" v-bind:class="[ activetab === 1 ? 'active' : '' ]">Tab 1</a>
    <a v-on:click="activetab=2" v-bind:class="[ activetab === 2 ? 'active' : '' ]">Tab 2</a>
</div>

<div class="content">
    <div v-if="activetab === 1" class="tabcontent">
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Title</th>
                    <th>Type</th>
                    <th>Available At:</th>
                </tr>
            </thead>
            <tbody>
            @foreach ($result as $id => $item)
                <tr>
                    <td>{{ $id }}</td>
                    @foreach($item as $subitem)
                    @if($subitem->name == "Task Title")
                        <td>{{ $subitem->task_comment }}</td>
                        <td>{{ $subitem->task_typet_id }}</td>
                        <td>{{ $subitem->available_at }}</td>
                    @endif
                    @endforeach
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>
    <div v-if="activetab === 2" class="tabcontent">
        TEST
    </div>
</div>
</div>


<script>
export default {
    el: '#tabs',
    data: { activetab: 1 },
};
</script>

Answer №1

Creating a new Vue instance with tabs functionality:
new Vue({
  el: '#tabs',
  data() {
    return {
      activetab: 1
    }
  },
})
.active {
  background-color: tomato;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="tabs" class="container">
  <div class="tabs">
    <a href="#" @click.prevent="activetab = 1" :class="[ activetab === 1 ? 'active' : '' ]">Tab 1</a>
    <a href="#" @click.prevent="activetab = 2" :class="[ activetab === 2 ? 'active' : '' ]">Tab 2</a>
  </div>

  <div class="content">
    <div v-if="activetab === 1" class="tabcontent">
      TEST 1
    </div>
    <div v-if="activetab === 2" class="tabcontent">
      TEST 2
    </div>
  </div>
</div>

Answer №2

Your hyperlink settings seem to be using array syntax, it may be beneficial to update it as follows:

<div class="tabs">
    <a v-on:click="activetab=1" v-bind:class="{ active: activetab === 1}">Tab 1</a>
    <a v-on:click="activetab=2" v-bind:class="{ active: activetab === 2}">Tab 2</a>
</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

What could be causing the d3.js pie chart transition to malfunction?

Today I am experimenting with d3.js to create a unique pie chart from scratch. While following tutorials here as my base, there were modifications made in the code to add personal touches and customization. The challenge arose during Step 6 when introduc ...

What is the best way to retrieve the modelValue from within a Vue 3 directive?

Here is a question: How can I access and update el.modelValue from a custom directive? directives: { currency: { mounted(el, binding, vnode, prevVnode) { console.log(vnode, prevVnode) el.oninput = (e) => { if (Numb ...

Struggling to display sub-categories correctly within the Categories Dropdown menu

Attempting to display sub-categories in the Categories Dropdown list In my code, I aim to display category and sub-category under the Category in the Products table. This is how my categories table looks: 1. public function up() { Schema::create(&apos ...

Obtaining a result from a switch statement

Here is a solution to populate the generated drop-down menu: $('dropdown_options').innerHTML = '&nbsp;'; jsonResponse.forEach(function(element){ $('dropdown_options').innerHTML += '<option value='+ elemen ...

`Can I embed inline .svg images into a Nuxt application?`

Is there a way to dynamically include an SVG HTML in a Vue Nuxt application and be able to style it? I tried creating a component but instead of the image, I am getting text data:image/svg+xhtml.... Any suggestions on how to resolve this issue? <templ ...

Retrieve the value of [routerLinkActive] in the component's class

Recently, I've been working on a tab component called TabComponent and it includes the following HTML template: <a [routerLink]='link' [routerLinkActive]="[is-active]">link label</a> <button>Close tab</button> The c ...

Is there a way to display this JSON data using mustache.js without needing to iterate through a

Here is the JSON data: var details = [ { "event": { "name": "txt1", "date": "2011-01-02", "location": "Guangzhou Tianhe Mall" } ...

Tips for removing the current item from a list by clicking on a close icon of the same class name

Is there a way to remove a list item after clicking on its close icon? I am using a JavaScript function to add items to the list. Please refer to the image and code below. Thank you! https://i.stack.imgur.com/aeASd.png The code snippet is as follows: f ...

Exploring the functionality of publicRuntimeConfig in Nuxt plugins

I have developed a new Vue socket.io plugin called @/plugins/socket-io.js import Vue from 'vue' import VueSocketIO from 'vue-socket.io' Vue.use( new VueSocketIO({ debug: true, connection: process.env.SOCKET_IO_CONNECTION, } ...

Tips on positioning a div based on the screen dimensions

In my table, there is an icon that reveals a chart as a popup when hovered over. This div is where the chart is displayed: <div id="chart-outer" style="@style" class="popup-chart close"> <h2 id="charttitle&q ...

An error occurred while trying to load the XMLHttpRequest due to a NetworkError that was

I have encountered an issue while working on a client-side project using jQuery, JavaScript, and various jQuery plugins. Our professor supplied us with a proxy.php file to fetch the required data for our web application. I incorporated the easy tab plugin ...

What is the best way to remove text using javascript?

Hey everyone! I am new to coding in javascript and I'm hoping for some help with stripping text. I have a string that is formatted like this: <iframe src="http://embed.videokoo.com/61YVek?client_file_id=390856&width=720&height=480" style=" ...

Vue's event trigger when an element is being destroyed

Is there a specific event in Vue that triggers when a v-if condition becomes false? For instance, if I need to assign a value to y when the div with id foo is no longer visible for some reason. What should I use instead of @whenDivGoes? <div v-if= ...

Can $location be modified without triggering its corresponding $route?

Can you update the location path in Angular.js without activating the connected route? For example, is there a way to achieve this (see pseudo code below): $location.path("/booking/1234/", {silent: true}) ...

Discovering the world of Promises in TypeScript and understanding how to return specific types

Transitioning from coding in Clojure for the past two years to TypeScript has been an interesting journey. However, I've hit a bit of a roadblock today. The issue lies with my interface: interface ICustomer { id: number, first_name: string } I ...

Submitting a form using an anchor tag in Angular 8: A step-by-step guide

I have a question about how to submit form data using hidden input fields when a user clicks on an <a> tag. <form action="/submit/form/link"> <input type="hidden" [attr.value]="orderNumber.id" /> <input type="hidden" [attr.value]= ...

Exploring the interception of ajax http responses beyond the scope of AngularJS

Is there a way to capture and manage http responses from outside of Angular? $httpProvider is not an option since the target script loads after Angular has initialized. I need a solution that functions similar to ajaxSuccess in jQuery. ...

Transferring an object from the factory to the controller

I'm currently working on setting up a factory that sends an ajax request to an API and then returns a data object. Here is the code snippet I have written: app.factory('Test', function($http, $q) { var data = {response:{}}; var getM ...

NodeJS has a knack for replying even before the function has completed

Struggling with a NodeJS and Express API for a school project. The getAuthUserId function is not working as expected. It decodes the JWT token to retrieve the user Id from the mongoDB server. However, when calling this function in a REST call "/user/authT ...

What is the reason behind the NgForOf directive in Angular not supporting union types?

Within my component, I have defined a property array as follows: array: number[] | string[] = ['1', '2']; In the template, I am using ngFor to iterate over the elements of this array: <div *ngFor="let element of array"> ...