首页 > 解决方案 > vue.js 中的“[Violation] 'click' 处理程序耗时 43665 毫秒”

问题描述

也许它渲染,这需要 xxMS。发生什么事?每当我关闭打印页面时,我都会在 chrome 控制台中收到此消息。有人解决这个问题吗?

<button @click="printScreen()" type="button">print</button>

<div ref="printparts">test</div>

    methods: {
          printScreen() {
            let value = this.$refs.printparts;
            let printPage = window.open();
            printPage.focus();
            printPage.document.body.insertAdjacentHTML('afterbegin', value.outerHTML);
            printPage.print();
            printPage.close();
          },
        },

标签: javascriptvue.jsrender

解决方案


您收到此违规警告的原因可能是因为事件处理程序在打印页面关闭之前不会返回。因此,当您单击按钮时,打印页面打开,然后在关闭打印页面之前什么都不会发生,然后函数返回。


推荐阅读