[英]TypeError: Cannot read property '$emit' of null ( "THIS" IS NULL)
I'm converting my project from JS to TS and I don't know why I cannot call "this" here.我正在将我的项目从 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>
this is log这是日志
app.js:sourcemap:161212 TypeError: Cannot read property '$emit' of null
In other file, I can still use "this" is method, but in this method I can not在其他文件中,我仍然可以使用“this”是方法,但在这种方法中我不能
[SOLVED] : I have already solved my problem. [已解决] :我已经解决了我的问题。 It caused because I forgot add this decorator
@Component({})
.这是因为我忘了添加这个装饰器
@Component({})
。 So pls add this when you caught this problem.因此,当您发现此问题时,请添加此内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.