As a beginner of Vue.js, I am trying to remove stylesheet which I added through the mounted
lifecycle in a component with
mounted() {
this.style = document.createElement('link');
this.style.type = "text/css";
this.style.href = 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css';
document.head.append(this.style);
}
This works fine. When I visit this page, I can see the effect of the Bootstrap. However, when I change to another component through router-view
, I want to remove this stylesheet to affect other pages. I tried remove
like appending the stylesheet, but it doesn't work:
unmounted() {
document.head.remove(this.style);
}
UPDATE
It seems that this works when I refresh the page or use $router.go(0)
to refresh it but how can I remove the stylesheet without refreshing the page.