What is the best way to set up a watcher for q-input and q-date components in Quasar

I have a component named "display.vue" which includes a date picker for users to select a date.

//display.vue
<template>
  <div class="q-pa-md" style="max-width: 300px">
    <q-input filled v-model="date" mask="date" :rules="['date']">
      <template v-slot:append>
        <q-icon name="event" class="cursor-pointer">
          <q-popup-proxy cover transition-show="scale" transition-hide="scale">
            <q-date v-model="date">
              <div class="row items-center justify-end">
                <q-btn v-close-popup label="Close" color="primary" flat />
              </div>
            </q-date>
          </q-popup-proxy>
        </q-icon>
      </template>
    </q-input>
  </div>
</template>

<script>
import { ref } from 'vue'

export default {
  setup () {
    return {
      date: ref('2019/02/01')
    }
  }
}
</script>

Additionally, I have a file named "displayData.js" that processes and filters data from the database.

//displayData.js
router.get("/", async function (req, res) {
  
  // Query to retrieve data from the database
  const query = 'SELECT * FROM database'
  ...
  
  // Display the filtered data
}

I am looking to capture the selected date by the user in displayData.js so that each time the user picks a date, the script will automatically query and filter data matching that specific date. What would be an effective way to achieve this? Would updating the selected date in the URL be a suitable approach?

Answer №1

Documentation from the QDate API states that the component triggers update:model-value each time its value is modified. To properly react to this event, you need to execute a function that will re-run your query function:

<q-date v-model="date" @update:model-value="runQuery">
  <div class="row items-center justify-end">
    <q-btn v-close-popup label="Close" color="primary" flat />
  </div>
</q-date>
methods: {
  runQuery(value) {
    displayData.queryFunctionName(value)
  }
}

In this context, queryFunctionName refers to the function within your router.get("/") code block. It's worth mentioning that using "router" as the name for an API fetch object can be confusing, as it's commonly associated with vue-router used for page navigation rather than data fetching.

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

Learn the process of connecting checkboxes to a database in MeanStack using Angular

Hey everyone, I'm currently working with AngularJS ng-repeat and I am trying to dynamically bind a checkbox based on a true or false value from the database. However, even when the database value is set to true, the checkbox does not automatically che ...

Add a new div in Javascript and include an HTML icon inside

This Django project includes a JavaScript function that generates a new div to display certain data. for (var i = 0; i < files.length; i++) { var newDiv = document.createElement('div'); newDiv.setAttribute("class" ...

What is the process for resetting a function within an AJAX Response?

I have implemented the code below in AJAX to switch tabs. $("a").click(function(event){ if ($.browser.msie != true && $.browser.version != 8.0){ event.preventDefault(); if ($(this).parent().hasClass("current") == false){ ...

SSE with FastAPI works correctly on a local environment, but encounters issues when deployed on Azure Web

After successfully setting up a basic notification system using SSE on our FastAPI server, we encountered an issue when deploying it to our Azure Web App. Although the server logs confirm that notifications are sent and consumed, they are not being receive ...

What is the best way to apply identical properties to multiple components at once?

With multiple components like <my-a>, <my-b>, and many more each having a prop: { props: { isDetail: { type: Boolean, default: false, } }, } When creating a form using these components, repeating the prop assignment becom ...

A concise way to write an else if statement in Javascript and jQuery

Is there a way to make this code more concise? It works perfectly fine, but it's too lengthy. Basically, the code involves two dropdown lists where the user selects options, and based on their selection, values appear in two textboxes. The catch is th ...

Loading external libraries in Angular2: A step-by-step guide

I'm currently working on incorporating a Datepicker in Angular 2, but I'm facing an issue where the library is not loading. This is causing a template parsing error stating 'material-datepicker' is not a recognized element: My System.c ...

Inject the value of a JavaScript array into an HTML element

Is it feasible to transfer a global javascript array value to an HTML tag, particularly within an img (title) tag? I'm curious if the following is achievable: <img src="_info.gif" height="26" width="37" title=myArray[5]/> If it is possible, p ...

"Unraveling nested data structures in React using JSON parsing

When attempting to fetch data in React from a MySQL database, I have encountered an issue where MySQL auto-escapes my values, including nested objects. While I am able to use the .json() function successfully on the top-level, I have run into problems when ...

Tips for repairing buttons in the CSS container

The buttons in the CSS search-box are not staying fixed as intended. They should be within the search box, but instead, they are protruding out of the panel. I attempted to utilize z-index, but it did not produce the desired outcome. https://i.sstatic.n ...

Issue with displaying checkboxes in the dataTable table

I am currently working with dataTables and encountering difficulties displaying checkboxes on my tables. Below is the code that I have: <table id="employeeList" class="table table-sm table-bordered table-hover" cellspacing="0" width="200%"> &l ...

Mastering the Art of Concise Writing: Tips to

Is there a way to write more concisely, maybe even in a single line? this.xxx = smt.filter(item => item.Id === this.smtStatus.ONE); this.yyy = smt.filter(item => item.Id === this.smtStatus.TWO); this.zzz = smt.filter(item => item.Id == ...

The formatting in the svg rendering from the object is not displaying correctly

I am working with a set of SVGs stored in an object: icon: { facebook: `<svg class="w-6 h-6 fill-current" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M30 ...

PHP question about maintaining data continuously

So, I've created this interesting JavaScript 'thing' with the help of jQuery and AJAX. The main concept behind it is that a div can be edited (contenteditable=true), which sparked the idea to develop a chatroom-like feature. It's pretty ...

Bringing in an npm package to a Single File component in Vue.js

I want to integrate Jodit into a Single File Component, but I'm unsure of the correct method. Although there is a wrapper called jodit-vue, I prefer to learn how to do it without using it for educational purposes. I have set up a Vue CLI project with ...

Error: Unable to locate module: Issue discovering 'crypto' and 'fs' modules

I am currently in the process of learning React and attempting to establish a connection between my React app and my database using the following code: var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: ...

Adjust the CSS of a dynamically generated jQuery checkbox button in real-time

I am working on a project where I am creating a series of jQuery checkboxes dynamically within a loop. Here is how I am doing it: var checkbox = $('<input>').attr({type: 'checkbox', id: checkbox_id); panel.append(checkbox); panel ...

Uncovering classes and selectors in CSS files that match an element with JavaScript

Trying to explain my idea with an example since it's a bit tricky. Imagine we have this HTML code: <ul> <li id="myli" class="myclass">Hello</li> </ul> along with the corresponding CSS: .myclass{ color:red; } li.m ...

When does an xmlHttpRequest object parse serialized XML into a DOM during its lifecycle?

When a JavaScript code with xmlHttpRequest.responseXML() runs, it creates a DOM Document object from the XML-structured HTTP response body. Have you ever wondered at what moment the XML string is turned into the DOM Document by an xmlHttpRequest object? ...

Error message "Unable to access property 'rotation' of an object that does not exist - Three.js"

I'm currently facing an issue where my code is executing as expected, but there are two errors popping up in the console saying "Cannot read property 'rotation' of undefined". It's puzzling because both variables are defined globally. I ...