How can you show the default calendar for a specific month and year in a Vue3 datepicker?

I've been utilizing the @vuepic/vue3datepicker component, which automatically shows the days of the current month when integrated in my project:

<template>
  <VueDatePicker v-model="date" inline></VueDatePicker>
</template>

However, I need to fetch the month and year from an API and display the corresponding month-year combination to the user, rather than showing the current month's days.

This objective can be easily accomplished by:

onMounted(() => {
  date.value = new Date(props.year, Number(props.month)-1, 1)
})

The challenge arises when I also require using the highlight prop (as I have a list of specific days within the selected month/year that need highlighting), necessitating the date attribute in v-model="date" to be an array:

<template>
  <VueDatePicker v-model="date" :highlight="highlightedDates" />
</template>

Hence, I am unsure about how to address this issue.

If you have any suggestions on how to tackle this, please share them with me.

Answer №1

If you want to store the value of new Date() in an array along with other new Date() values, it's completely feasible. Here is a sample code snippet showing how to create an array with one date:

date.value = [ new Date(props.year, Number(props.month)-1, 1) ]

You have the flexibility to use native Array functions like push, slice, or any others according to your requirements. Additionally, for the template's v-model to function correctly, consider adding the multi-dates prop as well.

  <VueDatePicker v-model="date" inline multi-dates></VueDatePicker>

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 receiving dual return values from an AJAX request

I am sending an array of table IDs to retrieve the table numbers associated with those IDs from the database. I need to add up all the default seats for each table ID and return the total. JAVASCRIPT : function showUser(str) { if ...

Generating an array of keys from duplicated values in Typescript

My data is structured in the following array format: { itemTitle: 'value example', itemType: 'value example', itemDescription: 'value example', itemFamily: 'Asset', }, { itemTitle: 'val ...

Struggles with vue, vite, and Ubuntu 20 glitches

I'm feeling puzzled. After successfully saving my code to GitHub from Windows, I tried to open the exact same code on Ubuntu, using the same versions of Vite and Vue. However, the app failed to compile and I encountered multiple errors while attempti ...

Can someone explain the function of statements such as (function () { // code; }.call(this)); within a JavaScript module?

By utilizing the Function.prototype.call() method, it becomes possible to create a function that can be applied to various objects. I delved into the code of , which had been minified and required to be un-minified for examination. The structure of the co ...

Changing an ng-repeat filter following the manual update of a text input

Utilizing jQuery auto-complete to automatically populate values as users type into a text input. <input type="text" ng-model="tags" name="tags" id="tags" value="" /> Subsequently, the ng-repeat is filtering content based on the entered text <di ...

I'm having trouble with my Discord app command. Every time I try to use it, I keep getting the error messages "The application did not respond" and "Dispatching MESSAGE_SEND_FAILED." How

Having a good amount of experience in JavaScript, I was optimistic about developing a Discord application as it seemed quite manageable. Eventually, I successfully integrated the bot into a server and implemented a command that is now listed in Discord&apo ...

The anticipated reply was supposed to consist of an array, however it ended up being an

I'm brand new to Angular and I've been searching for a solution to my issue with no luck. My app is supposed to retrieve data from a MongoDB database and display it to the user. However, I keep getting this error message: Error: [$resource:bad ...

What is the best way to create a fixed footer in Next.js using React?

I'm looking to create a fixed footer that will stay at the bottom of the page if there isn't enough content to fill it. I've been researching ways to achieve this using CSS, but many of the methods don't easily translate to React/Next.j ...

Creating a never-ending scroll feature on a static page in Next.js

I am in the process of creating a portfolio using Next.js and have a large number of projects on the page. I would like to implement a feature where images start loading only when they enter the current viewport. This functionality works well with the defa ...

I recently developed a T3 stack project and am currently attempting to configure a next JS middleware, however, I am encountering issues with it not triggering as expected

Having issues with my T3 stack app where the next js middleware is not triggering. I've placed a middelware.ts file in the root directory. middleware.ts // middleware.ts import { NextResponse } from "next/server"; import type { NextRequest ...

Incorporating source files from an Express server into an HTML document

Recently, I delved into the world of Node.js with Express and Socket.io to create a web application, specifically a game. In my project, I have a designated /public folder where I aim to serve the necessary files for the client-side operations. Typically, ...

Activate the element only when all input fields are completed. This function can be used repeatedly

I am working on developing a versatile function that will iterate through all input fields. If any of these fields are empty, I want to trigger the toggling of a class name (disabled) on another element (such as an anchor or button). Currently, the functi ...

Can you explain the variances between the index.html and index-async.html files within the AngularJS seed project?

Within the angularjs seed project, there are two files that appear to produce identical results: index.html and index-async.html. If you want to view the code for index-async.html, you can visit this link. Similarly, if you're interested in the code ...

Incorporating additional ES6 modules during the development process

As I build a React component, I find that it relies on an ES6 component that I'm currently developing. Since I created the latter first, what is the typical method to include it during development as I work on the second component? If the dependency w ...

Exploring the Vue JS loop using various components

Currently, I am utilizing Vue JS to create a list with a single generic list item component. In the scenario where an appropriate non-generic component exists that matches the correct type, a custom component will be employed. <email-queue-item v-for= ...

What is the best way to send the accurate data type from PHP to Javascript?

My approach involves using the jQuery post method to insert a record in MySQL. The issue I'm facing is that when comparing the output of the PHP using ==, all three conditionals function correctly. However, with ===, the first two conditionals return ...

Ways to verify if a user is authenticated without relying on request.session

I am currently developing a web application using Express, Docker, and following a Three-layered architecture. In my app, I store user login information in a session and have blogposts as a key resource. To retrieve the blogpostId from the database in the ...

What is the best way to utilize an onClick on a button to update a value that is being utilized in a useEffect hook?

I am looking for a way to dynamically change the content displayed in this section without navigating to another page. I have two sets of data - one displaying all blogs and the other showing only blogs authored by "mario". How can I implement a button cli ...

Utilizing React Material-Table to Trigger a React Component through Table Actions

I have set up a datatable using the code below. <MaterialTable icons={tableIcons} title={title} columns={columns} data={data} actions={[ { icon: () => <Edit />, t ...

Get the docx file as a blob

When sending a docx file from the backend using Express, the code looks like this: module.exports = (req, res) => { res.status(200).sendFile(__dirname+"/output.docx") } To download and save the file as a blob in Angular, the following code snippet i ...