Skip to content

Instantly share code, notes, and snippets.

@acabreragnz
Last active August 3, 2024 17:30
Show Gist options
  • Save acabreragnz/547860be7162d5b811b6afa1b679b6a8 to your computer and use it in GitHub Desktop.
Save acabreragnz/547860be7162d5b811b6afa1b679b6a8 to your computer and use it in GitHub Desktop.
Acapedia - Vue component using the featureFlagsMixin
<template>
<div>
<div :class="{'new-feature': isFeatureActive, 'old-feature': !isFeatureActive}">
<!-- Content goes here when MILESTONE_NEW_FEATURE_ENABLED is enabled/disabled -->
<button @click="fetchData">Fetch Data</button>
<div v-if="apiData">{{ apiData }}</div>
</div>
<p>{{ computedMessage }}</p>
</div>
</template>
<script>
import axios from 'axios';
import { featureFlagsMixin, MILESTONE_NEW_FEATURE_ENABLED } from '@/mixins/featureFlagsMixin';
export default {
name: 'MyComponent',
mixins: [featureFlagsMixin({
[MILESTONE_NEW_FEATURE_ENABLED]: 'isFeatureActive',
})],
data() {
return {
// Add property if the feature isFeatureActive is active
optionalDataField: this.isFeatureActive ? 'This is an optional value' : undefined,
apiData: null,
};
},
computed: {
computedMessage() {
return this.isFeatureActive
? 'The feature MILESTONE_NEW_FEATURE_ENABLED is enabled.'
: 'The feature MILESTONE_NEW_FEATURE_ENABLED is disabled.';
},
},
methods: {
async fetchData() {
if (this.isFeatureActive) {
try {
const response = await axios.get('https://api.example.com/data');
this.apiData = response.data;
} catch (error) {
console.error(error);
}
}
},
},
};
</script>
<style scoped>
.new-feature {
/* Styles go here when MILESTONE_NEW_FEATURE_ENABLED is enabled */
}
.old-feature {
/* Styles go here when MILESTONE_NEW_FEATURE_ENABLED is disabled */
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment