All files / src/components/u-anchor.vue index.vue

75% Statements 9/12
10% Branches 1/10
0% Functions 0/1
75% Lines 9/12

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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44      7x   7x     7x                                                                      
<template>
    <div
        :id="label || refName"
        :name="label || refName"
        anchor
        vusion-slot-name="default"
    >
        <s-empty v-if="(!$slots.default) && $env.VUE_APP_DESIGNER"></s-empty>
        <slot></slot>
    </div>
</template>
 
<script>
import SEmpty from '../s-empty.vue';
export default {
    name: 'u-anchor',
    components: { SEmpty },
    props: {
        name: { type: String, default: '' },
        label: { type: String, default: '' },
    },
    data() {
        return {
            refName: { type: String, default: '' },
        };
    },
    mounted() {
        if (this.$vnode) {
            this.refName = this.$vnode && this.$vnode.data && this.$vnode.data.ref;
        }
        const { hash } = location;
        const id = this.label || this.refName;
        if (hash && id && hash === `#${id}`) {
            this.$nextTick(() => {
                const node = document.querySelector(hash);
                if (node) {
                    node.scrollIntoView();
                }
            });
        }
    },
};
</script>