January 2, 2025
Jenkins vs GitHub Actions
I recently came across an interesting article by the team at Slack, where they share their experience migrating from Jenkins to GitHub Actions (GHA).
defineExpose() is a function used inside a component's setup() to specify which properties and methods should be accessible from the parent component.
This is especially useful when a child component needs to expose some of its methods or data so the parent component can interact with them.
Child Component (ChildComponent.vue)
<script setup>
import { ref, defineExpose } from "vue";
const count = ref(0);
function increment() {
count.value++;
}
// Expose the increment method and count property to the parent component
defineExpose({
increment,
});
</script>
<template>
<div>
<button @click="increment">Increase Count</button>
</div>
</template>
defineExpose({ increment }) is used to expose the increment() method to the parent component. This allows the parent component to call increment() from its own context.
Parent Component
<!-- ParentComponent.vue -->
<script setup>
import { ref } from "vue";
import ChildComponent from "./ChildComponent.vue";
const child = ref(null);
function callIncrement() {
// Call the increment method from the child component
child.value.increment();
}
</script>
<template>
<div>
<ChildComponent ref="child" />
<button @click="callIncrement">Call Increment from Parent</button>
</div>
</template>
The child component is referenced using ref. Then, the increment() method of the child component can be called via child.value.increment().