Ionic Vue is throwing an error indicating that a property is not found on the type '{ $route(currentRoute: any): void; }'

Currently, I am developing an Ionic WebApp using Vue and TypeScript. My current task involves retrieving the current id parsed by the route. To achieve this, I have been working on a watcher:

export default {
      data() {
        return {
          productId: null,
        };
      },
      watch: {
        $route(currentRoute: any) {
          this.productId = currentRoute.params.id;
        },
      },
    };
    

However, I encountered the following error message:

[vue-cli-service] TS2339: Property 'productId' does not exist on type '{ $route(currentRoute: any): void; }'.
    [vue-cli-service]     14 |   watch: {
    [vue-cli-service]     15 |     $route(currentRoute: any) {
    [vue-cli-service]   > 16 |       this.productId = currentRoute.params.id;
    [vue-cli-service]        |            ^^^^^^^^^
    [vue-cli-service]     17 |     },
    [vue-cli-service]     18 |   },
    [vue-cli-service]     19 | };
    

I have already attempted using the handler notation without success. Does anyone else have a suggestion to resolve this issue?

Answer ā„–1

  watch: {
    "this.$route.params.productId": {
      handler: function(val) {
        this.productId = val
        console.log(val);
      },
      // deep: true,
      immediate: true
    }
  },

By setting the immediate option to true, the callback will be triggered immediately with the current value of the expression.

Answer ā„–2

To activate type inference in components, simply utilize Vue.extend() on the exported component definition:

import Vue from 'vue'
                    šŸ‘‡
export default Vue.extend({
  data() {
    return {
      productId: null,
    }
  },
  watch: {
    $route(currentRoute: any) {
      this.productId = currentRoute.params.id
    }
  }
})

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

The local storage gets wiped clean whenever I am using this.router.navigate

I am in the process of building a website using Angular 5 and Typescript. One important aspect of my implementation is utilizing localStorage to store the JWT Token for user login. Whenever I click on a link (either Home or any other link), I implement a ...

Vue3 Composition API: Issue with Computed Property not Refreshing

In the process of developing a Nuxt project, I find myself in need of determining the size of the wrapper to make adjustments to the grid settings (I aim for a single-line layout, which could potentially be achieved through CSS by hiding certain elements) ...

Is there a way to alphabetically sort V-Chips in Vuetify?

Hello, I'm currently attempting to organize multiple V-Chips alphabetically. Does anyone have any suggestions? Here is the code snippet I am working with. I want to display all my V-Chips in alphabetical order. Should I sort my array or is there a sp ...

Utilize the "yaminncco/vue-sidebar-menu" package to customize the sidebar menu elements according to the user's role

Greetings! Currently, I am utilizing Laravel Breeze in conjunction with Inertia JS. For the sidebar, I have integrated the "yaminncco / vue-sidebar-menu package". I am curious to find out if there is a method to dynamically display menu elements ...

Significance of v-slot directive with activator bound to the value of "on"

After examining the Vuetify example code for v-toolbar, what exactly does v-slot:activator="{ on }" serve? Consider the following snippet as an example: <template v-slot:activator="{ on }"> <v-toolbar-title v-on="on"> <span>All< ...

Different ways to categorize elements of Timeline using typescript

I have some code that generates a timeline view of different stages and their corresponding steps based on an array of stages. Each stage includes its name, step, and status. My goal is to organize these stages by name and then display the steps grouped un ...

Activate the field once the input for the other field is completed

I have a form where the last name field is initially disabled. How can I make it so that the last name field becomes enabled only when the first name is inputted? <form> <label for="fname">First name:</label><br> ...

PrimeNG's p-table in Angular is not being recognized when using @ViewChild

Here is the code snippet I am referring to: import { DataTable } from 'primeng/primeng'; @Component({ moduleId: module.id, templateUrl: 'search.component.html' }) export class SearchComponent { @ViewChild(DataTable) pr ...

The outcome of a promise is an undefined value

I am facing an issue where I need to access the result of my API call outside the promise, but the value I receive is always undefined. Within the OrderService : public async getOrderPrice(device: string) : Promise<any> { this.urlOrderPrice = th ...

Combine all TypeScript enums into a single one

Looking for a way to combine two separate enums into one for easier use. export enum ActionTypes1 { ClearError = 'CLEAR_ERROR', PrependError = 'PREPEND_ERROR', } export enum ActionTypes2 { IncrementCounter = 'INCREMENT_COUNT ...

Parent component does not receive Vue.js $emit when multiple calls are made in rapid succession

Recently, I attempted to create a basic notification system utilizing the Notification Store concept influenced by Linus Borg's code snippet available at: https://jsfiddle.net/Linusborg/wnb6tdg8/ The functionality works flawlessly when adding notifi ...

What is the best way to access firebase information using vue and vuefire?

I'm struggling to understand how to effectively retrieve Firebase data in a Vue application. Iā€™m prepared to delete this question or even consider leaving my position as a programmer if I can't find a solution ;) I realize that the data is asy ...

Experiencing a Typescript error when trying to access a property within a nested object

My current challenge involves typing an object, which seems to be error-free until I try to access a nested property and encounter the dreaded red squiggle. After some research, I came across suggestions like this: type FlagValue = string | boolean | numb ...

Acknowledgment Pop-up

When using the PrimeNG table with a custom modal component that I created, I encountered an issue. The edit functionality works correctly and retrieves the correct row id, however, the delete function always returns the id of the first row. dashboard.html ...

The issue persists in Angular 5 and asp.net MVC where the ID number continues to increase despite being deleted

Currently, I am using Angular 5 (VS CODE) for the front-end and asp.net mvc/entity framework (VS2017) for the back-end. My CRUD methods are functioning properly; however, I have encountered an issue where the ID of a newly created row keeps increasing even ...

I want to know the most effective way to showcase particular information on a separate page using Angular

Recently, I've been working with a mock json file that contains a list of products to be displayed on a Product page. My goal is to select a specific product, such as 'Product 1', and have only that product's information displayed on th ...

My HTML files are not recognizing the IONIC Property within their own objects

As I delve deeper into understanding Angular and Ionic, a peculiar issue has arisen for which I seek a solution. I have several export classes containing HTML forms. In each corresponding .ts file, I declare a variable and import the relevant model to bin ...

Only displaying the VUE slot when the content meets a certain criteria

I have encountered a situation where I have two routes rendering the same component but with different data from an API source. The component in question has a child component called <base-section> that utilizes a v-if directive to determine whether ...

Using Laravel to retrieve data from an API and display it with VueJS

Recently delving deeper into the world of Laravel, I found myself pondering the most effective method to pass data from my controller to my Vue component. While I have grasped the concept of passing data as a prop, I am struggling to achieve the desired r ...

Using TypeScript generics to create reusable type definitions for reducers

I have a common reducer function that needs to be properly typed. Here's what I have come up with: export interface WithInvalidRows<T extends { [K in keyof T]: InvalidCell[] }> { invalidRows: T; } interface AddPayload<S extends WithInval ...