生产环境调用vue devtool的脚本

1,310 阅读1分钟

前端同学大多常用技术栈都是简单易上手的vue。平时项目开发中配合使用vue-devtools如鱼得水。但是现网环境出现状况,如何快速定位问题呢?下面的骚操作让你调试现网环境就像开发时一样。 Talk is cheap. Show me the code.

var Vue, walker, node;
walker = document.createTreeWalker(document.body,1);
while ((node = walker.nextNode())) {
  if (node.__vue__) {
    Vue = node.__vue__.$options._base;
    if (!Vue.config.devtools) {
      Vue.config.devtools = true;
      if (window.__VUE_DEVTOOLS_GLOBAL_HOOK__) {
        window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit("init", Vue);
        console.log("==> vue devtools now is enabled");
      }
    }
    break;
  }
}

F12打开控制台,Console下复制粘贴上面代码,敲下回车,关闭控制台,再次打开就看到熟悉的vue tab了

vue.jpg