效果展示
pc
移动端
固定加载模式:
index.html引入文件
<script src="https://cdn.bootcdn.net/ajax/libs/eruda/3.0.1/eruda.min.js"></script>
// 初始化
<script>eruda.init()</script>
!!!可直接在BootCDN下载,建议存到自己服务器。
Vue/html根据字段动态加载模式:
const data = {} // data为后台数据
// 判断控制台开关
const scriptElement = document.querySelector(
'script[data-custom-attribute="custom-value"]' // 自定义一个script标签和属性
);
if (data.customString.includes("custom-yes")) { // 根据某个值判断引入,如果有就引入
if (!scriptElement) { // 没有创建过才创建
const initScript = document.createElement("script");
initScript.setAttribute("data-custom-attribute", "custom-value");
initScript.textContent = "eruda.init()";
document.body.appendChild(initScript);
}
} else {
if (scriptElement) { // 没有就删除,防止有
document.body.removeChild(scriptElement);
}
}
感谢你的阅读,如对你有帮助请收藏+关注!
只分享干货实战和精品,从不啰嗦!!!
如某处不对请留言评论,欢迎指正~
博主可收徒、常玩QQ飞车,可一起来玩玩鸭~