Exploring the functionality of utilizing dual loops with v-for in Vue.js

I am facing an issue with my table code where I need to repeat it 6 times to match the day column above. I would like to use v-for and make use of a variable called "count" which represents the number of days. Can someone assist me with this task?

<table class="table table-hover table-bordered">
    <thead>
        <tr>
            <th scope="col" rowspan="2">Dosen</th>
            <th scope="col" colspan="11" v-for="(hari, index) in hari" :key="index">{{hari.nama}}</th>
        </tr>
        <tr>
            ...
        </tr>    
    </thead>  
    <tbody>
        <tr v-for="(dosen, index) in dosen" :key="index">
            <th scope="row">{{dosen.nama}}</th>
        </tr>
    </tbody>  
</table>

The desired output can be viewed at: https://i.sstatic.net/URzVx.png

This is the script for retrieving the data:

 <script>
onMounted(() =>{
    if(!token) {
        return router.push({
        name: 'Login'
        })
    }

    // Retrieving days
    axios.defaults.headers.common.Authorization = `Bearer ${token}`
    axios.get('http://localhost:8000/api/hari')
    .then(response => {
    // Storing response data in state variables
    hari.value = response.data.data         
    count.value = response.data.count
}).catch(error => {
    console.log(error.response.data)
})

// Retrieving time slots
axios.defaults.headers.common.Authorization = `Bearer ${token}`
axios.get('http://localhost:8000/api/jam')
.then(response => {
    // Storing response data in state variables
    jam.value = response.data.data         
}).catch(error => {
    console.log(error.response.data)
})

// Retreiving teachers/lecturers
axios.defaults.headers.common.Authorization = `Bearer ${token}`
axios.get('http://localhost:8000/api/dosen')
.then(response => {
    // Assigning response data to state variables
    dosen.value = response.data.data         
}).catch(error => {
    console.log(error.response.data)
})
})

Answer №1

Is this solution suitable for your requirements?

<template v-for="i in [1, 2, 3, 4, 5, 6]" :key="i">
  <th scope="col" colspan="1" v-for="jam in jam" :key="jam">{{jam.kode}}</th>
</template>

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

Why is my Next.js scroll event not triggering when scrolling?

useEffect(() => { document.addEventListener("scroll", ()=> { console.log('.................gotcha'); }); },[]); I am trying to trigger an event when the user scr ...

Retrieve information from various MongoDB collections

Greetings! I currently have a database with the following collections: db={ "category": [ { "_id": 1, "item": "Cat A", }, { "_id": 2, "item": "Cat B" ...

Create a variety of elements in real-time

My goal is to utilize JavaScript in order to generate a specific number of input boxes based on the user's input. However, I encountered an issue where using a for loop only creates one input box and then appends this same input box multiple times. f ...

What methods are available to verify all my (JavaScript) AJAX calls when they are being sent to Node.js?

My web app sends hundreds of HTTP requests to a Node.js API I created. I need to ensure that only authenticated requests are accepted by Node.js. The issue at hand: I don't want to manually update each AJAX request in my JavaScript code to include a ...

Is it achievable to dynamically generate new pages on initial load in NextJS?

Right now, I am utilizing getStaticProps and getStaticPaths to pre-render a specific number of articles before my website goes live. This method works effectively, but if a new article is created and displayed on the front page while the site is still acti ...

Error message stating that there is no property 'collection' in Firestore when using Firebase v9 modular syntax in Firebase Firestore

Working on a React application that makes use of Firebase Firestore for handling database operations, I recently upgraded to Firebase version 9 and adopted the modular syntax for importing Firebase services. Nevertheless, when attempting to utilize the co ...

Activate/Deactivate toggle using Vue.js

new Vue({ el: '#app', data: { terms: false, fullname: false, mobile: false, area: false, city: false, }, computed: { isDisabled: function(){ return !this.terms && !this.fullname && !this.mob ...

Is it possible to retrieve data from the server in Node.js/Vuetify based on a specific time frame?

I'm currently using a node.js server for my vuetify project. Within the server, I am parsing a csv file that contains scheduling and time information. Is there a method in my vuetify project to retrieve data from the csv file based on the current time ...

Impose a delay between the execution of two functions in React.js

Looking for a way to introduce a forced delay between two consecutive function calls. Essentially, what I want to achieve is: a // call func a delay(100) // pause for 100 ms b // call func b Is there a method to accomplish this? Update: attempted a() ...

PHP - Extract Information from Table Upon Form Submission without User Input

I'm facing a challenge with my web form that includes a table allowing users to delete rows before submitting. Although there are no input fields in the table, I need to capture the data from these rows when the form is submitted. The issue is that th ...

"Step-by-Step Guide to Dividing and Centering Text Sections with Dynamic

Initially, my intention is to implement the concept outlined below. The webpage has dual potential states. In the first scenario, two texts (with potentially varying lengths) are centralized together as a header. When transitioning to the second state, the ...

Guide on how to programmatically assign a selected value to an answer using Inquirer

Currently, I'm utilizing inquirer to prompt a question to my users via the terminal: var inquirer = require('inquirer'); var question = { name: 'name', message: '', validation: function(){ ... } filter: function( ...

What is the process for indicating an option as "chosen" within Embedded JavaScript Templating (EJS)?

I've been working on a function that allows users to modify each other's data, including the ability to change roles. I'm having trouble getting the select form to display the current role of a user with the "selected" attribute. This is wh ...

What are the essential Angular 2 observables for me to utilize?

I have created a form input for conducting searches. Upon user input into the search bar, I want to trigger calls to two separate APIs simultaneously. Here is my current attempt: myInput: new FormControl(); listOne: Observable<string[]>; listTwo: Ob ...

What is the reason for my algorithm's inability to work with this specific number?

I'm currently working on creating an algorithm to compute the sum of prime numbers that are less than or equal to a specified number. Below is my attempt: function calculatePrimeSum(num) { // initialize an array with numbers up to the given num let ...

leveraging AJAX to showcase information retrieved from a MySQL database

Hello! I am brand new to PHP and have little knowledge of AJAX. I am in the process of creating a photo gallery site and have used the following code to display my photos. I would like to make it possible, using AJAX or any other language, for someone to c ...

Implementing a Javascript solution to eliminate the # from a URL for seamless operation without #

I am currently using the pagepiling jQuery plugin for sliding pages with anchors and it is functioning perfectly. However, I would like to have it run without displaying the '#' in the URL when clicking on a link like this: www.mysite.com/#aboutm ...

Should I retain a duplicate of the js library in the lib or vendor directory even if it has already been installed using npm?

Query 1 : As I install my project dependency libraries using npm, they are saved in the npm_modules folder. I wonder if it's necessary to also duplicate the library files like angular.js, angular-route.js in a separate lib or vendor folder for permane ...

transferring data from a web page to a php script seamlessly without navigating away

I've already spent a significant amount of time searching on Stack Overflow and Google, but I haven't found a solution that works for me. My issue is that I have an HTML form and I need to send the data to PHP without redirecting or leaving the ...

Leveraging vuex within a vue component that has been mounted manually

I've been manually mounting a component onto a dynamic element using Vue.extend with the following code snippet: import Vue from 'vue'; import MyComponent from 'MyComponent.vue'; const MyComponentConstructor = Vue.extend(MyCompon ...