无法分配给对象'[object Object]'的只读属性'disconnectedHandler'

时间:2019-11-21 19:31:39

标签: javascript salesforce lwc

我正在尝试使用Salesforce Lightning中的计时器。当我将其添加到页面时,它引发错误“ render在'c:serviceConsoleCaseTimer”中引发了错误[无法分配给对象'[object Object]'的只读属性'disconnectedHandler'] “我不知道如何解决此错误。  这是我收到此错误的代码:

set tabclosed(value){
        this._tabclosed = value;
        this.tabisclosed = this._tabclosed;
        if(this.tabisclosed){
            this.disconnectedHandler();
        }
    }


    constructor(params){
        super(params)

        this.disconnectedHandler = this.disconnectedHandler.bind(this)
        this.pauseTimer = this.pauseTimer.bind(this)
     }

    connectedCallback() {
        if(this.autoStart){              
            this.start();
        }
        window.addEventListener("beforeunload", this.disconnectedHandler); 
    }       

    // Function for detecting window navigation/closing 
    disconnectedHandler(){
        if(this.stime !== '00:00:00'){       
        this.stop();        
        newSession({caseId: this.recordId, timeVal: this.stime}).then(() => {
            })
            .catch(error => {
            });
        }
    }

我知道该属性是只读的。我试图将属性设置为writable:true。

这是我尝试过的链接: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Read-only https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty

Ngrx : Cannot assign to read only property 'Property' of object '[Object]' https://salesforce.stackexchange.com/questions/219610/workspace-api-not-returning-focused-tab-details

谢谢您的帮助!

0 个答案:

没有答案