I'm converting my project from JS to TS and I don't know why I cannot call "this" here.
<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
[SOLVED] : I have already solved my problem. It caused because I forgot add this decorator @Component({})
. So pls add this when you caught this problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.