1๐
โ
You can listen to beforeDestroy
lifecycle method and remove the script from your document.
To do that, you need to save the DOM element created from you appendChild
in your Vue component and remove the script tag in beforeDestroy
lifecycle.
methods: {
dynamicallyLoadScript(url) {
var script = document.createElement("script");
script.src = url;
this.scriptEle = document.body.appendChild(script);
}
}
beforeDestroy() {
document.body.removeChild(this.scriptEle);
}
๐คKong
0๐
You can add an id for that script tag, and later in the destroyed() method you can get that script calling it by id and delete it.
๐คraar
Source:stackexchange.com