[Vuejs]-I want to remove one script tag from page in vuejs and laravel

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

Leave a comment