This document explains the transformation of the Evolution Framework application from vanilla JavaScript to Vue.js 3 using CDN.
querySelector and getElementByIdinitializeXXX() functionsv-model, v-show, v-for@click directivev-show and v-ifExample Transformation:
<!-- Before: Vanilla JS -->
<button class="nav-btn active" data-view="dashboard">Dashboard</button>
<!-- After: Vue.js -->
<button
v-for="view in navigationViews"
:key="view.key"
class="nav-btn"
:class="{ active: activeView === view.key }"
@click="setActiveView(view.key)">
</button>
// Global variables
let assessmentScores = { swadharma: 0, operating: 0, ... };
let currentAssessment = { pillar: 'swadharma', ... };
data() {
return {
assessmentScores: { swadharma: 0, operating: 0, ... },
currentAssessment: { pillar: 'swadharma', ... },
// All state centralized in Vue component
}
}
// Manual event listener attachment
nextButton.addEventListener('click', handleNextQuestion);
pillarSelectButtons.forEach(button => {
button.addEventListener('click', () => {
const pillar = button.dataset.assess;
selectPillarForAssessment(pillar);
});
});
<!-- Declarative event handling -->
<button @click="handleNextQuestion">Next</button>
<button
v-for="(pillar, key) in pillarMappings"
@click="selectPillarForAssessment(key)">
</button>
// Manual DOM manipulation
function updateDashboardScores() {
Object.entries(assessmentScores).forEach(([pillarKey, score]) => {
const pillarElement = document.querySelector(`[data-pillar="${pillarKey}"] .pillar-score`);
if (pillarElement) {
pillarElement.textContent = `${score}%`;
pillarElement.className = 'pillar-score';
if (score >= 61) pillarElement.classList.add('high');
}
});
}
<!-- Reactive rendering -->
<div class="pillar-score" :class="getScoreColorClass(assessmentScores.swadharma)">
%
</div>
initializeNavigation(), initializeAssessment(), etc.data() propertiescomputed properties for derived statemethods for event handlers and actions// Automatic UI updates when data changes
assessmentScores: {
swadharma: 0,
operating: 0,
// ... other pillars
}
computed: {
currentPillarData() {
return this.pillarMappings[this.currentAssessment.pillar];
},
overallProgress() {
const scores = Object.values(this.assessmentScores);
return Math.round(scores.reduce((sum, score) => sum + score, 0) / scores.length);
}
}
v-for: Loop rendering for listsv-show/v-if: Conditional renderingv-model: Two-way data binding:class: Dynamic class binding@click: Event handlingmounted() {
this.loadAssessmentData();
if (this.activeView === 'progress') {
this.$nextTick(() => {
this.updateRadarChart();
});
}
}
evolution/
├── index.html # Original vanilla JS version
├── app.js # Original vanilla JS logic
├── vue-index.html # New Vue.js HTML template
├── vue-app.js # New Vue.js application logic
└── style.css # Shared CSS (unchanged)
v-modelfunction showPillarModal(pillarKey) {
const modal = document.getElementById('pillar-modal');
modal.classList.remove('hidden');
// Manual content updates
}
showPillarModal(pillarKey) {
this.modal = {
show: true,
pillar: this.pillarMappings[pillarKey],
// Reactive updates
};
}
v-for@clickTo migrate existing applications to Vue.js:
data()The Vue.js transformation provides:
The reactive nature of Vue.js eliminates much of the manual DOM manipulation required in vanilla JavaScript, while providing a more structured and predictable development experience.