Class-Based Components
<template>
<EjsButton type="info" @click="toggleMessageVisibility()">
{{ buttonLabel }}
</EjsButton>
<div v-if="messageVisible" class="message">
{{ message }}
</div>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
import {
EjsButton,
} from '@/components';
@Component({
components: {
EjsButton,
}
})
export default class ExampleComponent extends Vue {
/* --------------- Data --------------- */
private messageVisible!: boolean = false;
private target!: string = 'World';
/* --------------- Props --------------- */
@Prop()
private greeting: string = 'Hello';
/* --------------- Computed --------------- */
get buttonLabel() {
return this.messageVisible
? 'Hide Message'
: 'Show Message';
}
get message() {
return `${this.greeting}, ${this.target}`;
}
/* --------------- Methods --------------- */
private toggleMessageVisibility(visibleState?: boolean) {
visibleState === undefined
? this.messageVisible = !this.messageVisible // Toggle
: this.messageVisible = visibleState; // Set To Arg
}
}
</script>Last updated