I have this vue component that displays a full size image after being created when a user clicks an image on a carousel. When this is open, the user should not be able to scroll the page. Currently the way I've implemented this is by directly styling the documentElement with overflow:hidden; or overflow:auto; when the component is created or destroyed.
My questions is whether this is acceptable, or if there is a way in which I can use the virtual DOM for example. I know that directly interfering with the DOM generally is bad practice, but I can't seem to find a way to make it work. I've tried using this.$root.$el.style but that does not seem to work either.
<script>
export default {
props: ['imageSrc'],
created() {
document.documentElement.style.overflow = 'hidden';
},
beforeDestroy() {
document.documentElement.style.overflow = 'auto';
},
};
</script>