我试图从一个方法访问一个变量,但我得到:
类型“{ toggleCommentLikeVisible: () => void;”上不存在属性“commentLikeVisible”;
这是我的代码:
<template>
<div
class="moments-item"
data-index="0"
>
<div class="item-right">
<div class="item-ft">
<div
class="item-reply-btn"
@click="toggleCommentLikeVisible"
>
<span class="item-reply" />
</div>
<CommentLikeModal
v-if="commentLikeVisible"
/>
</div>
</div>
</div>
</template>
<script lang="ts">
import CommentLikeModal from '@/components/CommentLikeModal.vue';
export default {
name: 'MomentItem',
components: {
CommentLikeModal
},
data() {
return {
commentLikeVisible: false
}
},
methods: {
toggleCommentLikeVisible: function() {
this.commentLikeVisible = !this.commentLikeVisible;
}
}
}
</script>
我已经尝试过 toggleCommentLikeVisible()
而不是
toggleCommentLikeVisible: function()
结果相同。
我不知道那里可能出了什么问题。
最佳答案
我认为这是一个警告/错误,因为你有 <script lang="ts">
如果您编辑脚本标签,它似乎会在我创建的示例项目中消失 <script>
关于typescript - 无法从 Vue.js 中的方法访问数据(使用 Ionic),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64624732/