最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "[Violation] 'click' handler took 43665ms" in vue.js - Stack Overflow

programmeradmin0浏览0评论

Maybe it render, that took xxMS. What happen? Anytime I close the print page, I receive this message in the chrome console. Does anyone fix this problem?

<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();
          },
        },

Maybe it render, that took xxMS. What happen? Anytime I close the print page, I receive this message in the chrome console. Does anyone fix this problem?

<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();
          },
        },
Share Improve this question edited Mar 1, 2020 at 4:48 Tom asked Mar 1, 2020 at 4:30 TomTom 211 silver badge3 bronze badges 2
  • Can you also please show us the code for the button and for the event listener? – Sydney Y Commented Mar 1, 2020 at 4:32
  • Sorry, I have edit my question, please review on it. Thanks – Tom Commented Mar 1, 2020 at 4:50
Add a ment  | 

2 Answers 2

Reset to default 4

The reason why you are getting this violation warning is likely because the event handler doesn't return until the print page is closed. So, when you click the button the print page opens, then nothing happens until the print page is closed, then the function returns.

I used onmouseover and Chrome doesn't show the violation, but Performance say Warning.

printScreen() {
        let value = this.$refs.printparts;
        let printPage = window.open();
        printPage.focus();
        printPage.document.body.insertAdjacentHTML('afterbegin', value.outerHTML);
        printPage.onmouseover = function() {
          printPage.print();
          printPage.close();
        };
        return false;
      },
发布评论

评论列表(0)

  1. 暂无评论