I've incorporated the Element-UI NavMenu component into my web application to create a navigation bar using Vue.JS with TypeScript.
In order to achieve this, I have created a Vue component within a directory called "navBar," which contains the following:
The navBar.vue component:
<template src="./navBar.html">
</template>
<script src="./navBar.ts" lang="ts">
</script>
The content of navBar.html:
<div id="navbar">
<el-menu
mode="horizontal"
:select="handleSelect"
background-color="rgba(95, 75, 139, 1)"
text-color="#fff"
active-text-color="rgba(255, 255, 255, 1)">
<el-menu-item index="1">Item 1</el-menu-item>
</el-menu>
</div>
And the TypeScript code in navBar.ts:
import Vue from 'vue'
import Component from 'vue-class-component'
export default class NavBar extends Vue {
handleSelect (key: string, keyPath: string) {
console.log(key, keyPath)
}
}
However, upon clicking on "Item 1," I encounter an error:
[Vue warn]: Property or method "handleSelect" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
I'm puzzled by this issue and would appreciate any insights or suggestions.
I've reviewed similar queries like this one, but none seem to address the use of TypeScript specifically.