ts报错:Property 'webkitRequestFullscreen' does not exist on type 'HTMLElement'

ts报错:Property ‘webkitRequestFullscreen’ does not exist on type ‘HTMLElement’

在vue项目中引入了ts 要是先全屏及推出全屏效果

 fullScreen() {
        // let el:any;
        var el = document.documentElement;
        var rfs = el.requestFullscreen || el.webkitRequestFullscreen || 
            el.mozRequestFullScreen  || el.msRequestFullScreen ;
        if(typeof rfs != "undefined" && rfs) {
            rfs.call(el);
        } else if(typeof window.ActiveXObject != "undefined") {
            //for IE,这里其实就是模拟了按下键盘的F11,使浏览器全屏
            var wscript = new ActiveXObject("WScript.Shell");
            if(wscript != null) {
                wscript.SendKeys("{F11}");
            }
      }
    }

报错:Property ‘webkitRequestFullscreen’ does not exist on type ‘HTMLElement’

解决方式:document的返回值用any类型去承接


fullScreen() {
        let el:any;
         el = document.documentElement;
        var rfs = el.requestFullscreen || el.webkitRequestFullscreen || 
            el.mozRequestFullScreen  || el.msRequestFullScreen ;
        if(typeof rfs != "undefined" && rfs) {
            rfs.call(el);
        } else if(typeof window.ActiveXObject != "undefined") {
            //for IE,这里其实就是模拟了按下键盘的F11,使浏览器全屏
            var wscript = new ActiveXObject("WScript.Shell");
            if(wscript != null) {
                wscript.SendKeys("{F11}");
            }
      }
    }
完美解决报错!!

你可能感兴趣的:(ts报错:Property 'webkitRequestFullscreen' does not exist on type 'HTMLElement')