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?
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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With