Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property does not exist on the type in vue-class-component

I got an error in my TypeScript component file that a prop doesn't exist, but I declared the prop exactly as described in the vue-class-component documentation example.

Property 'propMessage' does not exist on type 'MyComponent'.Vetur(2339)

How do I fix this?

screenshot of error

like image 705
Jon Sud Avatar asked Sep 12 '19 07:09

Jon Sud


People also ask

Does not exist on type Vue?

To fix the "Property does not exist on type 'Vue'" error, we can add the missing property into TypeScript type definition file. to add the type definition for . vue files by exporting Vue as a default export within the declare module statement.

How do I add external js to Vue?

Add a script tag inside your Vue component template. This is the easy fix I have found. Just add the script into the component template. But don't forget to add, type="application/javascript" to the script tag otherwise it will show an error during the build. However, if you have added document.

How do I add a JavaScript file to Vue?

There are two ways to import a JavaScript library to the Vue Component. The first is to import a local JavaScript library. Here, you can import the JavaScript library by using the 'import' keyword inside the script tag of your Vue file. import * as mykey from '../assets/js/mykey.

Can you use JavaScript in Vue?

Every piece of your future application/web page in Vue is a component. Components represent encapsulated elements of your interface. In Vue. js, components can be written in HTML, CSS, and JavaScript without dividing them into separate files.


1 Answers

The documentation you linked states:

Following is the example written in Babel. If you are looking for TypeScript version, it's in the example directory.

Example:

<script lang="ts">
    import Vue from 'vue';
    import { Component } from 'vue-class-component';

    const AppProps = Vue.extend({
      props: {
        propMessage: String
      }
    })

    @Component
    export default class YourComponent extends AppProps {

        get something() {
            return this.propMessage;
        }
    }
</script>
like image 151
JKL Avatar answered Oct 18 '22 18:10

JKL