Explore the world of watching and references using typescript and vue-property-decorator

I'm inquiring about watches and refs. The situation is that I have a vswitch with a v-model where the setter action takes quite a bit of time to complete (involving writes to the store and numerous updates on the DOM).

An issue arises when Vue executes the action before rendering the new value of the switch. Ideally, I would like to display the input value immediately as it changes. My workaround involves "watching" the switch's inputValue and triggering the setter action when the value is changed.

My question revolves around implementing this functionality using TypeScript and vue-property-decorator. To tackle this problem, I added a ref to my switch element and attempted the following approach:

@Watch("$refs.switch.inputValue", {
    immediate: true,
    deep: true,
})
change() {
    alert('value changed');
}

I am wondering if it is possible to achieve this behavior using the @watch decorator in Vue?

Answer №1

If you're trying to watch $refs using @Watch in Vue, it won't work because $refs aren't reactive. Instead, consider using events. This is particularly useful when working with Vuetify's v-switch component. You can listen for the change event like this:

<v-switch @change="valueChanged()"/>

...

valueChanged() {
  // handle change event
}

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

What could be the issue causing Vue to not start up properly?

I have been working on a Rails application and have integrated some Vue components into the pages. The components range from simple dynamic lists to more complex implementations with nested components. Let me walk you through how it all functions with som ...

What is preventing this from being a function?

It appears that the authenticationProvider is missing for some reason. @autoinject() export class ProviderManager implements AuthenticationManager { constructor( private container: Container ){ } public authenticate( creds: Credentials ): Promis ...

Create seamless communication between Angular application and React build

I am currently engaged in a project that involves integrating a React widget into an Angular application. The component I'm working on functions as a chatbot. Here is the App.tsx file (written in TypeScript) which serves as the entry point for the Rea ...

"Presenting Invoice Information on an Invoice Template: A Step-by-Step Guide

Currently, I am working with Laravel 5.7 and VueJs 2.5.*, where I have a table of invoices. My goal is to create a new component that will display a specific invoice based on user selection, allowing them to view or print the chosen invoice. I am still ex ...

Automatically generated bizarre URL parameters

Something strange is happening all of a sudden. I've noticed unusual URL parameters appearing on the site, and I'm not sure where they are coming from in my code. https://i.stack.imgur.com/g1xGG.png I am using Webpack 4 and Vue. This issue is ...

Jest's expect method fails to capture errors thrown by async/await functions

I'm currently experimenting with a TypeScript-Express application that utilizes MongoDB and Mongoose. To perform testing, I have integrated jest and mongo-memory-server into the project. While I have succeeded in testing the insertion of new documents ...

Transform an Hstore to a Map instance

I'm struggling to convert a string that looks like this: "'keyTest'=>'valueTest', 'keyTest2'=>'valueTest2',..." into a Map object easily. I can achieve it using forEach, but I'm wondering i ...

What is the procedure for incorporating a cookie jar into axios using typescript?

I encountered an issue while trying to add a cookie jar to an axios instance. The problem arises because the interface AxiosRequestConfig does not have a member named "jar". Is there any way to enhance the existing AxiosRequestConfig type or is there a wor ...

Broadening Cypress.config by incorporating custom attributes using Typescript

I'm attempting to customize my Cypress configuration by including a new property using the following method: Cypress.Commands.overwrite('getUser', (originalFn: any) => { const overwriteOptions = { accountPath: `accounts/${opti ...

Async function causing Next JS router to not update page

I'm diving into the world of promises and JavaScript, but I've encountered an issue while working on a registration page following a tutorial on YouTube. Currently, I am using next.js with React and TypeScript to redirect users to the home page i ...

Guide on how to conditionally display a button or link in a Next.js Component using TypeScript

Encountering a frustrating issue with multiple typescript errors while attempting to conditionally render the Next.js Link component or a button element. If the href prop is passed, the intention is to render the Next.js built-in Link component; otherwise, ...

Is there a way to transpile a dependency within the node_modules directory when using Nuxt 2?

I have come across challenges when transpiling node_modules with Nuxt, but the latest version of Nuxt (2.0) seems to have addressed this issue by introducing a transpile option in the nuxt.config.js file. https://nuxtjs.org/api/configuration-build/#transp ...

Fetching the present locale within a nested component

I am having trouble extracting the locale parameter from vue-i18n in my child component. I successfully set up vue-i18n in cli ui and using $t("message") for translation works fine. However, I encounter an error when trying to access the i18n.locale prope ...

What is the best method for implementing a Twitch <script> tag within Vue.js?

In an effort to replicate the functionality I achieved in Angular here, I am now attempting to do so within Vue.JS (2.6+). My goal is to utilize the Twitch API for embedding a Stream, which currently only offers usage through inline HTML: <script src= ...

Retrieving information from a JSON source to populate a data table

Hello fellow developers... I'm currently facing an issue while trying to dynamically populate a data table with information fetched through a fetch request and stored in a Vuex instance variable. Here is the relevant code snippet: <script> impo ...

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=& ...

What is the best way to apply multiple array filters to an object list in react.js?

Looking to filter an array of items using multiple filter arrays in order to display only the items that match all selected filters. For example: The main array contains a table with the following data: ID TypeID LocationID Name 1 2 ...

My React project is unable to locate a file after I modified its extension from .js to .tsx

After using npx create-react-app my-app to start my React project and adding Typescript, I encountered an issue after converting one of my components to a .tsx file. The error message I received was: Module not found: Error: Can't resolve './cont ...

The VueJS app seems to be experiencing difficulties with rendering the content

Just starting out with VueJS and I have my initial files - index.html and index.js. I want to stick with just these two files and not add any more. Here's the content of index.html: <html lang="en"> <head> <meta charset ...

Pressing the close button will shut down all bootstrap models

Is there a way to fix an issue where closing Model2 also dismisses the main Model? In my code, there is a button "Launch modal" to open the Model, and within the Model, there is a button "Launch modal2" to open a new model called Model2. However, when ...