【问题标题】:Cannot access data from a method in Vue.js (with Ionic)无法从 Vue.js 中的方法访问数据(使用 Ionic)
【发布时间】:2021-02-13 21:09:01
【问题描述】:

我正在尝试从方法访问变量,但我得到: Property 'commentLikeVisible' does not exist on type '{ toggleCommentLikeVisible: () => void;

这是我的代码:

<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() 结果相同。

我不知道那里可能有什么问题。

【问题讨论】:

  • 它应该可以工作,我模拟你的代码here 它工作正常
  • @BoussadjraBrahim 我知道,我不明白为什么它不起作用,可能是 ionic 的东西吗? (它也为我工作了一天左右,然后我开始无缘无故地收到错误消息!)
  • 可能是一些讨厌的内部 nodejs 缓存。你能删除node_modules 并重新安装吗?
  • @Iyashi 刚刚删除了 Ionic 项目并再次创建它,没有任何更改。错误总是存在
  • @TarikMokafih 将项目导入codesandbox,因为您的项目中必须有一些不同的东西,其他项目工作正常吗?

标签: typescript vue.js ionic-framework


【解决方案1】:

我认为这是一个警告/错误,因为您有 &lt;script lang="ts"&gt; 如果您编辑脚本标签,它似乎在我创建的示例项目中消失了 &lt;script&gt;

【讨论】:

    猜你喜欢
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 2021-03-26
    • 1970-01-01
    • 2017-10-02
    • 2021-10-28
    • 2018-02-23
    相关资源
    最近更新 更多