Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as external from '~/components/helper/external.js'
- mounted(){
- external.initialize_body_script('/js/custom/main.js'); //
- },
- // PROJECT/src/assets/external.js
- function head_script(src) {
- if(document.querySelector("script[src='" + src + "']")){ return; }
- let script = document.createElement('script');
- script.setAttribute('src', src);
- script.setAttribute('type', 'text/javascript');
- document.head.appendChild(script)
- }
- function body_script(src, defer=false) {
- if(document.querySelector("script[src='" + src + "']")){ return; }
- let script = document.createElement('script');
- script.setAttribute('src', src);
- script.setAttribute('type', 'text/javascript');
- if(defer){
- script.setAttribute('defer', 'true');
- }
- document.body.appendChild(script)
- }
- function initialize_body_script(src){
- del_script(src);
- body_script(src);
- }
- function initialize_head_script(src){
- del_script(src);
- head_script(src);
- }
- function del_script(src) {
- let el = document.querySelector("script[src='" + src + "']");
- if(el){ el.remove(); }
- }
- function head_link(href) {
- if(document.querySelector("link[href='" + href + "']")){ return; }
- let link = document.createElement('link');
- link.setAttribute('href', href);
- link.setAttribute('rel', "stylesheet");
- link.setAttribute('type', "text/css");
- document.head.appendChild(link)
- }
- function body_link(href) {
- if(document.querySelector("link[href='" + href + "']")){ return; }
- let link = document.createElement('link');
- link.setAttribute('href', href);
- link.setAttribute('rel', "stylesheet");
- link.setAttribute('type', "text/css");
- document.body.appendChild(link)
- }
- function del_link(href) {
- let el = document.querySelector("link[href='" + href + "']");
- if(el){ el.remove(); }
- }
- export {
- head_script,
- body_script,
- del_script,
- head_link,
- body_link,
- del_link,
- initialize_body_script,
- initialize_head_script,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement