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

Tips for displaying two dynamic variables that are interdependent

For instance: Controller: AllBooks[{ book1:{ hardcover{price:25.99},e-book{price:1.99} } }, book2:{ hardcover{price:60.00},e-book{price:2.99} }]; $scope.bookchoice = function(selectedBook) { $rootScope.choice = selectedBook;} $scope.booktype = functio ...

Shorten a value within an array of objects using JavaScript

How can I truncate a value in an array of objects based on specific criteria? Let's use the following example: var items = [ { name: "CN=arun, hjsdhjashdj,jsdhjsa,kshd", status: "Present" }, { name: "CN=manohar, abcdefghij,111111,2222222", s ...

Ways to maintain/preserve authenticated user session across different domains in Laravel

I am managing a multi tenancy build using Laravel. Currently, I have a main website main.com where users are able to register. Upon registration, a tenant (subdomain) website is created and the user is redirected to a new subdomain tenantB.main.com. H ...

Is it possible to combine multiple jQuery selectors for one command?

I need some help with jQuery commands. I have two similar commands, but not exactly the same. Here are the commands: $("#abc > .className1 > .className2 > .className3"); $("#pqr > .className1 > .className2 > .className3"); Is there a w ...

"Exploring the possibilities of Ajax in conjunction with Sol

I recently completed a tutorial on Ajax Solr and followed the instructions in step one. Below is the code I wrote: header.php: <script type="text/javascript" src="static/js/ajax-solr/core/Core.js"></script> <script type="text/javascript" s ...

Creating a personalized and versatile table component with unique functionality: where to begin?

Looking to create a versatile table component that can adapt for both desktop and mobile versions. If the screen width is below 720px, it should display a table using div, ul, li elements with a "load more" button at the bottom. If the screen width i ...

Utilizing Node.js callback for validating JWT tokens

In my Node.js server, I have set up an authentication route to authenticate requests: app.get('/loggedin', auth, function(req, res){ console.log(req.authenticated); res.send(req.authenticated ? req.authenticated: false) }) From what I u ...

Is there a way to change HTML retrieved from an AJAX request before inserting it into the document?

I am utilizing an ajax call to retrieve an HTML page from the server; the ajax call is structured as follows: function loadHtml() { $.ajax({ type : 'GET', async : false, url : &apos ...

405 Error Code: Unsupported Method – Laravel, Node.js, and Axios

I'm attempting to make a POST request from my Node.js server. In my Node file, I have the following: axios.defaults.baseURL = domain + '/api/server'; const getRaffle = () => { axios.post('/giveaway/getRaffle') .th ...

Can you explain the significance of 1x, 3x, etc in the Karma code coverage report for Angular unit testing?

I am a beginner when it comes to Unit Testing in Angular. Recently, I set up karma with code coverage using angular-cli. After running the command ng-test, I checked out the code coverage report and noticed references like 1x, 3x, etc. next to my code line ...

"Troubleshooting Nextjs in a Production Environment: Tips for Resolving Local Debugging Issues When

Everything is working flawlessly in my nextjs development setup. The build process goes smoothly without any issues. However, when attempting to serve the production locally, an error pops up saying: "Error: Element type is invalid: expected a string (for ...

Looking for a way to add interactivity to this canvas rectangle?

ctx.fillStyle = "#9b958c"; ctx.fillRect(sampleRectX, sampleRectY, sampleRectW, sampleRectH); ctx.fillStyle = "#fff"; ctx.fillText("Click here to play again.", sampleTextX, sampleTextY); This clickable rectangle has been giving me some trouble. While I fou ...

Please upload the image by clicking the "Upload Files!" button instead of relying on the input change

I am looking to enhance my image uploading process by allowing users to upload multiple images after clicking the Upload Files! button, rather than relying on the input change event. Below is the jQuery code I am using (which I found here): index.html &l ...

Generate a text string by choosing options from a form

Greetings! I have a form for creating a file, where the file name is determined by user selections. It's similar to "display text as you type" mentioned here, but my form includes radio buttons in addition to a textbox. For example: Textbox: "Name gi ...

Analyzing Dynamic Content

Currently, I am engaged in content parsing and have successfully executed a sample program. To demonstrate, I have utilized a mock link which you can access below: Alternatively, you can click on this link: Click Here In the provided link, I have parsed ...

Achieving this result in HTML using a jQuery accordion component

Hey there, I'm looking to create a full-height accordion that extends from the bottom to the top of the page, similar to what you see on this website: . I also have a footer positioned below the accordion. The content should load when the page loads ...

Transform js into a more dynamic format to avoid redundancy when displaying items upon click

I came across a simple lightbox code snippet, but it's based on IDs and I plan to use it for more than 20 items. I don't want to manually write out 20 JavaScript lines when there could be a more efficient way to handle it dynamically. My JS skill ...

Presenting a Random Term from an Array in Dual Locations

<input type="button" id="btnSearch" value="Search" onclick="myFunction();" /> <div id="message"> <p></p> </div> <br> <div id="message"> <p></p> </div> <script type="text/javascript"&g ...

Navigate to a different HTML file following a JavaScript function in Ionic and AngularJS with Cordova

I am currently creating an Android application in Cordova Tools for Visual Studio using Ionic and AngularJS. My goal is to redirect to another HTML page once my function has completed its execution, but I'm having trouble getting it to work correctly ...

Trouble arises when attempting to showcase document fields in MongoDB

As a beginner in programming, I am putting in my best effort to figure things out on my own. However, I seem to be stuck without any guidance. I am attempting to display all products from the mongoDB based on their brand. While I have successfully set up a ...