[Vuejs]-Wrap template component with his name

0👍

I can’t imagine why you would want to be do that but anyhow you could do the following

Vue.component('search', {
    name: 'search',

    template: `<div :class="wrapperClass">
        <div>component template</div>
    </div>`,

    computed: {
        componentName() {
            return this.$options.name
        },

        wrapperClass() {
            return `component-${this.componentName}`
        },
    }
})

Leave a comment