我对打字稿很陌生。现在,我已经设置了 nuxt(bridge with typescript) 应用程序并创建了一个名为 menuIcon 的组件;
<div class="container">
<div class="menu-icon" :class="active ? 'change' : ''" @click="toggle">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
<div
class="overlay"
:class="active ? 'overlay-slide-right' : 'overlay-slide-left'"
@click="toggle"
id="overlay"
>
<!-- html contents here -->
</div>
</div>
</template>
<script lang="ts">
export default {
data(){
const active:boolean=false;
return{
active
}
},
methods: {
toggle():void{
this.active= !this.active
},
},
};
</script>
<style scoped>
/*css contents here*/
}
</style>
它在浏览器中运行,但我在终端中看到以下错误。
TS2339: Property 'active' does not exist on type '{ toggle(): void; }'.
41 | methods: {
42 | toggle():void{
> 43 | this.active= !this.active
| ^^^^^^
44 | },
45 | },
46 | };
ERROR in components/MenuIcon.vue:43:27
TS2339: Property 'active' does not exist on type '{ toggle(): void; }'.
41 | methods: {
42 | toggle():void{
> 43 | this.active= !this.active
| ^^^^^^
44 | },
45 | },
46 | };
显然这是关于打字的事情,但我不知道如何解决它。我非常感谢任何人向我阐明这些问题。提前致谢。