Come on, my recommendation is to create style classes that you want to apply on the body for the proper size of font-size
.
Ai in your Vue component you make the logic to apply the classes in the body dynamically, example:
In your Assets/css/main.css:
.small-font-size {
font-size: 12px;
}
.medium-font-size {
font-size: 16px;
}
.large-font-size {
font-size: 20px;
}
Load this . css into your project, it does not need to be associated with any component.
Ai in its component responsible for changing font size:
<template>
<div>
<button type="button" @click="smaller" :disabled="isSmallest">Diminuir fonte</button>
<button type="button" @click="bigger" :disabled="isBiggest">Aumentar fonte</button>
</div>
</template>
<script>
export default {
name: 'FontSizeController',
data() {
return {
fontSize: 2 // vamos dizer que 2 é medium, 1 é small e 3 é large
};
},
computed: {
isSmallest({ fontSize }) {
return fontSize == 1;
}
isBiggest({ fontSize }) {
return fontSize == 3;
}
},
methods: {
smaller() {
if (this.fontSize > 1) {
this.fontSize--;
this.updateBodyFontSize();
}
},
bigger() {
if (this.fontSize < 3) {
this.fontSize++;
this.updateBodyFontSize();
}
},
updateBodyFontSize() {
const body = document.querySelector('body');
switch (this.fontSize) {
case 1:
body.classList.add('small-font-size');
body.classList.remove('medium-font-size');
body.classList.remove('large-font-size');
break;
case 2:
body.classList.add('medium-font-size');
body.classList.remove('small-font-size');
body.classList.remove('large-font-size');
break;
case 3:
body.classList.add('large-font-size');
body.classList.remove('medium-font-size');
body.classList.remove('small-font-size');
break;
}
},
}
}
</script>
So Matheus, did you look at the official documentation before you asked the question? Is there a session explaining about that.
– fernandosavio
Okay, but I don’t see where I can put that data in the body?
– Matheus França