如何在Vue中检测关闭的窗口(新标签)?

时间:2019-05-18 04:56:58

标签: javascript laravel vue.js window detection

需要注意该窗口是打开还是关闭... 它在使用SetInterval并提前关闭窗口时有效,但是,如何检测何时没有SetInterval真正关闭并触发它...

<template>
<button class="btn btn-info" @click="OpenTask('http://google.com')">Open window</button>
</template>

<script>
export default {
        data() {
            return {
                window: null,
                task:[],
            }
        },
        mounted() {
        },
        beforeDestroy() {
        },
        watch: {
        },
        methods: {
            OpenTask(url){
                var that = this;
                Vue.prototype.surf = window.open(url,'_blank');
                this.window = this.surf.closed;
                setInterval(function e () {
                    console.log(that.surf.closed);
                }, 7000);
                if(that.surf.closed)){
                console.log(that.surf.closed);
                this.window = this.surf.closed;
                }}
            },
        }
    }
    </script>

实际上没有检测到何时关闭窗口...如何制作?

0 个答案:

没有答案