繁体   English   中英

类型错误:无法读取 null 的属性“$emit”(“THIS”为 NULL)

[英]TypeError: Cannot read property '$emit' of null ( "THIS" IS NULL)

我正在将我的项目从 JS 转换为 TS,但我不知道为什么我不能在这里调用“this”。

<template>
  <transition name="modal">
    <div class="modal-mask">
      <div class="modal-wrapper">
        <div class="modal-container">
          <div class="modal-body">
            <div class="text-right">
              <label>
                <span>
                  <v-icon name="times" scale="1.5" />
                  <button
                    @click="closeModal"
                    type="button"
                    class="btn btn-sm btn-outline-info btn-block"
                    style="display: none"
                  >
                    Cancel
                  </button>
                </span>
              </label>
            </div>
            <h4 class="text-center title-switch">
              <span style="font-weigth: bold">{{ title }}</span
              >リストに追加しますか?
            </h4>
            <div class="d-flex justify-content-center align-items-center mb-2">
              <button @click="closeModal" class="btn btn-no mr-5">No</button>
              <button @click="getDate" class="btn btn-yes">Yes</button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script lang="ts">
import { Vue, Prop } from 'vue-property-decorator';
import { chatModule } from '@/store/modules/manage-chat';

export default class ModalConfirm extends Vue {
  @Prop(String) readonly title!: string;
  @Prop(Boolean) readonly check!: boolean;


  closeModal(): void {
    if (confirm('Close the window without saving?')) {
      chatModule.actionChangeNgListState({
        status: false,
      });
      this.$emit('close');
    }
  }
}
</script>

这是日志

app.js:sourcemap:161212 TypeError: Cannot read property '$emit' of null

在其他文件中,我仍然可以使用“this”是方法,但在这种方法中我不能

[已解决] :我已经解决了我的问题。 这是因为我忘了添加这个装饰器@Component({}) 因此,当您发现此问题时,请添加此内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM