All files / src/utils linkpao.js

7.14% Statements 1/14
0% Branches 0/3
0% Functions 0/2
7.14% Lines 1/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24    7x                                          
import Vue from 'vue';
 
Vue.prototype.$linkpao = async (url, target = '_self') => {
    try {
        let realUrl;
        if (typeof url === 'function') {
            realUrl = await url();
        } else {
            realUrl = url;
        }
        const a = document.createElement('a');
        a.setAttribute('href', realUrl);
        a.setAttribute('target', target);
        document.body.appendChild(a);
        a.click();
        setTimeout(() => {
            document.body.removeChild(a);
        }, 500);
        return true;
    } catch (error) {
        return true;
    }
};