Creating a flexible array in VUE.JS

(I would like to mention that I am utilizing the v-calendar plugin) I recently started working with vue.js and have been facing a challenge for some time now. I am trying to track button clicks and pass this information down to a component by toggling the value of Click from 0 to 1. However, I also want the highlight attribute to change from red to green based on this click event, but I am unsure how to achieve this reactivity. The specific error I encounter is related to this line:

highlight: (Click === 0 ? "red" : "green"),

Parsing error: Unexpected token, expected ")"

I require assistance in updating the highlight property to turn green when Click changes to 1. Below is the code snippet:

<template lang="html">
  <div class="container-fluid wrap">
    <vc-calendar is-dark :attributes="attributes(Click)"/>
    {{ Click }}
    <br />
    <!-- {{ Change(Click) }} -->
    <br>
  </div>
</template>

<script>
export default {
  name: "Calander",
  props: {
    Click: {
      type: Number,
      default: 0
    }
  },
  data()
  {
      return{
        attributes(Click):
        [
          {
            key: "today",
            highlight: (Click === 0 ? "red" : "green"),
            dates: new Date()
          }
        ]
      }
  },
  // computed: {
  //   Change(Click) {
  //     return Click === 0 ? "red" : "green";
  //   }
  // },
};
</script>

<style lang="css" scoped>
.wrap {
  background-color: #ffe277;
  text-align: center;
  padding: 3rem 0rem 3rem 34rem;
}
</style>

Answer №1

It appears that the syntax you have used is incorrect, it should be within the computed section.

  computed:
  {
        attributes() {
         return             
         [
          {
            key: "today",
            highlight: (this.Click === 0 ? "red" : "green"),
            dates: new Date()
          }
         ]
        }
  },

Additionally, in your HTML code, it should be formatted as follows:

<vc-calendar is-dark :attributes="attributes"/>

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 turning on a gaming controller before using it

Current Situation In my ionic side menu app, I have a main controller called 'main view'. Each tab in the app has its own controller, which is a child of the main controller. The issue I'm facing is that when I start the app, the first cont ...

What is the process for sending a message from the internet to a mobile device?

We are currently in the process of developing a website that sends SMS alerts to users for specific services, however I am struggling to set up a script that can perform this function. If anyone has any suggestions or recommendations for a solution, pleas ...

What is the best approach to selectively insert a portion of a fully loaded page from $.ajax(), all while running embedded scripts?

Currently, I am utilizing the $.ajax() function to load new pages on my website under specific conditions (such as the presence of a flash-based radio player). However, I am looking for a solution that does not involve altering the server-side output in th ...

I am experiencing an issue where the jquery sleep function is not being executed during

I currently have an Ajax request that is awaiting a response from another process. function checkProcess() { var flag = 0; while (flag === 0) { $.ajax({ url: "cs/CheckForProcess", async: false, success: ...

Tips for establishing default values in a form within the MEAN Stack framework

Just starting out with MEAN stack and Angular 6. Working on a web application using the MEAN Stack and looking to pre-fill default values in a form after clicking a button. In order to achieve this, I plan to create a function for the button that will acc ...

Tips for implementing a settimeout function in a VUEJS script

I'm currently working on my first Vue.js application and I'm facing an issue with the initial data upload in the script. After modifying the data received from a database call, I encounter an error during the page's initial load which resolv ...

Issue with implementing setCallBack for updating variant prices in Shopify

I'm currently attempting to update the price of a product when a variant is chosen. I've tried implementing the following code, but haven't been successful in getting it to function properly. The script has been added to the theme.liquid fi ...

Ways to resolve Error: Project needs yarn, but it is not currently installed

Just finished setting up my new project using the following commands: npm install --global yarn vue create elecprog yarn serve (-> encountered an error) Running everything through VS Code terminal. PS D:\elcp\elecprog> yarn serve yarn run ...

What is the best way to retrieve the height of a <DIV> element without factoring in the presence of a horizontal scrollbar with

I have created a unique jQuery plugin that involves utilizing two nested <DIV> elements. The outer div is set with a fixed width and overflow: scroll, while the inner div (which is wider) houses the content for scrolling purposes. Everything is fun ...

`Problem encountered in establishing a database table through jQuery ajax`

I am completely new to utilizing jQuery and ajax. Currently, I am experimenting with creating a table on my local MySQL server using a JavaScript file that sends SQL statements to a .php file for execution. Here is the code in the .js file: function exec ...

Exploring Angular2: The Router Event NavigationCancel occurring prior to the resolution of the Route Guard

My application has routes protected by an AuthGuard that implements CanActivate. This guard first checks if the user is logged in and then verifies if certain configuration variables are set before allowing access to the route. If the user is authenticated ...

Stop span elements from being removed within a `contenteditable` container

I am facing a challenge with an editable div that contains a span element which I would like to prevent users from deleting. My development environment is Vue3. Currently, if the user presses backspace while their cursor is to the right of the span or sel ...

Assign an AJAX call to retrieve data from a MySQL table and store it in a

In my database, I have a table that includes fields for 'user_name' and 'user_round'. My goal is to set the 'user_round' field to match the value of a JavaScript variable called 'Level'. However, when I run my code, ...

Exploring the discrepancies in utilizing the i18n library versus directly incorporating locale from JSON in vue.js

Recently, I decided to incorporate Chinese language into my Vue app. To achieve this, I loaded the entire JSON text into Vuex and utilized the stored text directly, instead of relying on an i18n library. I'm curious to know if there are any potential ...

How can the loader method be triggered from within a React component?

Utilizing a loader from react-router-dom to retrieve data for the component. Additionally, there is another function embedded within the component that updates certain information obtained through the loader. I am seeking a method to retrigger the loader ...

Learn the best way to efficiently transfer multiple checkbox selections in a single object using AJAX

In my form, I have 4 checkboxes with unique IDs like filter_AFFILIATION_1, filter_AFFILIATION_2, and so on up to 4. My goal is to dynamically send the values of checked checkboxes to the server using an ajax call. Below is the snippet of my code: $(&a ...

Guide on implementing OrbitControls to a camera imported from a glTF file

I am facing an issue with OrbitControls.js when trying to apply it to a loaded camera in a three.js scene. While the camera and model load successfully, the OrbitControls.js seem to work only with cameras created directly in the three.js using new THREE.Pe ...

Add an image tag to the Canvas element

I'm attempting to add an image to a canvas element. Consider this code snippet (http://jsfiddle.net/n3L6e1wp/). I am aiming to replace the text shown in the canvas with an img tag. I have attempted to substitute the content of the div with: <img s ...

Jest encounters a TypeError when interacting with Bootstrap-Vue

I am currently utilizing Bootstrap-Vue ^2.23.1 along with Vuejs and vue/compat ^3.2.45, and my testing library is jest ^29.3.1. However, when I include the BootstrapVue plugin in my tests, it triggers the following error: TypeError: Cannot read properties ...

The variable that is extracted from a JSON object within an array successfully logs to the console inside a loop. However, when attempting to use the same variable for summation

I have a looping task where I need to add the values of certain objects together in an array. While I can successfully log the values individually, like this: console.log(workouts[0].exercises[0].break); When I try to incorporate them into a loop, I enco ...