Using the boolean result from an array in Vue3 with v-if

I encountered an issue with handling content visibility in my project.

I needed to toggle the visibility of content using v-if, but the content was stored in an array. Here is an example of what I had:

<v-expansion-panel v-for="item in flightOptionData" :key="item.type" elevation="0" class="rounded-lg foExpansion">
    <v-expansion-panel-title class="pa-3 bg-card" v-slot="{ open }" expand-icon="" collapse-icon="">
        <section class="foCard">
            <p>{{item.finalPrice}}</p>
            <p>{{item.number}}</p>
            <p v-if="true" class="nextDay">+1</p>
        </section>
    </v-expansion-panel-title>
</v-expansion-panel>

<script>
    data() {
        return {
            flightOptionData: [
                { finalPrice: '5.431,00', number: 'A12314', overnight: true }, 
                { finalPrice: '5.431,00', number: 'A12314', overnight: false }
            ]
        }
</script>

I attempted to address this by making the following adjustments:

<v-expansion-panel v-for="item in flightOptionData" :key="item.type" elevation="0" class="rounded-lg foExpansion">
    <v-expansion-panel-title class="pa-3 bg-card" v-slot="{ open }" expand-icon="" collapse-icon="">
        <section class="foCard">
             <p>{{item.finalPrice}}</p>
             <p>{{item.number}}</p>
             <p v-if="{{item.overnight}}" class="nextDay">+1</p>
        </section>
    </v-expansion-panel-title>
</v-expansion-panel>

<script>
    data() {
        return {
            flightOptionData: [
                { finalPrice: '5.431,00', number: 'A12314', overnight: true }, 
                { finalPrice: '5.431,00', number: 'A12314', overnight: false }
            ]
        }
</script>

Answer №1

There seems to be a syntax error present in your code:

<p v-if="{{item.overnight}}" class="nextDay">+1</p>

The corrected syntax should be:

<p v-if="item.overnight" class="nextDay">+1</p>

Refer to the documentation for Vue's template syntax for further clarification

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 personalizing your jQuery image preview script

Currently, I have implemented a jQuery script that allows me to preview multiple images before uploading them. Although the functionality works well, I am facing difficulties customizing it to meet my specific requirements. <script> $(document).r ...

Enhance website security with X-ray standard user agent

Currently working on a Node.js application and utilizing the X-Ray library along with Request-X-Ray as a driver. I am curious to find out which user-agent X-Ray uses by default. Can anyone provide insights on this? ...

Session availability extends to subdomains, even though it may not be visible in a physical

Currently in the process of building a website Red Sec using a single account for all subdomains: Latest Updates Community Forum Personal Blog News Feed Support Us All pages share the same layout with different content by linking them to . Below i ...

Troubleshooting error messages in the console during conversion of image URL to Base64 in AngularJS

While attempting to convert an image URL to Base64 using the FromImageUrl method, I encountered an error in my console. Access to the image located at '' from the origin 'http://localhost:8383' has been blocked due to CORS policy ...

aviary usage resulted in a file_get_contents error

I successfully integrated aviary into my webpage and it's functioning properly. However, I'm encountering an issue with using the file_get_contents command to retrieve the saved image. Here's the aviary code: JS: <!-- Load Feather code ...

Is there a way to display a success message once the button has been activated?

<template> <div> <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control" v-model="firstName" placeholder="Enter ...

Are your Promises.all functions executing at the incorrect timing?

I can't seem to understand why Promise.all is not working as expected. Even though the log shows that data for "Streak" and "Last Activity" is successfully retrieved towards the end, I want Promise.all to fetch the data only when everything is filled ...

What's the advantage in using 2 functions instead of just utilizing one?

When I'm asking for help with my code, I make sure to include all of it in case there's a connection between the different functions. Recently, I received assistance to get one of my functions working properly. Specifically, I'm looking at t ...

The Jquery append function is limited to the initial ajax request, necessitating a page refresh in order to populate another div with the desired

When making an AJAX request to retrieve a JSON array, upon successful completion another AJAX request is triggered. The retrieved data is then populated into the div of a bootstrap modal using the jQuery append function. Everything functions as expected ...

How can I invoke a personalized function in angularjs from HTML?

One way to organize methods within js controllers is by defining them separately like this: angular.module('test').controller('mycontroller', mycontroller); function mycontroller() { //do something }; function ...

Using the spread operator in the console.log function is successful, but encountering issues when attempting to assign or return it in a

Currently facing an issue with a spread operator that's really getting on my nerves. Despite searching extensively, I haven't found a solution yet. Whenever I utilize console.log(...val), it displays the data flawlessly without any errors. Howev ...

The conversion from a relative path to an absolute path in Node is producing unexpected results

Hello everyone, I'm facing a problem with the function sendDownload(), specifically with the objPathArray parameter that I am receiving in this format: [{"pathToFile":"./REPORTS/portfolio/onDemand/Portfolio_report_HP_17.08.2021.xlsx","file":"Portfolio ...

Styling an active link in Next.js using Styled Components

Looking for a way to customize the active link style using styled components. I have a navigation bar where the currently active link should have a specific style applied. Any suggestions are appreciated! import React from 'react' import Link f ...

Seeking out the correct method for structuring loops and callbacks within nodejs with an emphasis on asynchronous operations

I've been researching multiple posts and articles on this topic, but I'm still struggling to grasp it. In my Mongoose model, there's a piece of code dedicated to inviting people to a project. When given a list of invitees, the code checks i ...

"When a Vuex mutation modifies the state, the computed property fails to accurately represent the changes in the markup

I've encountered a perplexing issue with using a computed property for a textarea value that hasn't been addressed in a while. My setup involves a textarea where user input is updated in Vuex: <textarea ref="inputText" :value="getInputText" ...

Selenium in C#: Timeout issue with SendKeys and Error thrown by JS Executor

Attempting to insert the large amount of data into the "Textarea1" control, I have tried two different methods. The first method successfully inserts the data but occasionally throws a timeout error, while the second method results in a JavaScript error. A ...

What is the best way to shut down a browser using C#?

After clicking the Login button, I want to automatically close the browser if the login is successful. protected void btnLogin_Click(object sender, AuthenticateEventArgs e) { if (isAuthenticated) { // close the browser } } Since I am not using AJAX, thi ...

Compact looped slideshow

Currently in the process of designing a website and looking to incorporate a unique photo gallery feature. The concept is as follows: The photo gallery will be displayed in a rectangular/box shape. There are a total of 10 photos, with only 7 initially vis ...

Retrieving Distinct Values in CouchDB

In my database, there are documents that represent different rooms. Each room has properties like "floor" and "hotel", among others. What I need to do is fetch all the floors associated with a specific hotel from the database. Something like getAllFloorsOn ...

Download the browser version of UglifyJS 2 now

Is there a way to download the browser version of UglifyJS 2 without having to build it myself? I'm running into issues with the manual installation. I used npm to install uglify-js, but I can't seem to find where to execute the uglifyjs --self ...