improved performance of vue modules

This commit is contained in:
Luca Haid
2025-08-04 12:15:21 +02:00
parent 32189b8899
commit 073ce045b9
13 changed files with 365 additions and 397 deletions
+23 -36
View File
@@ -1,25 +1,18 @@
// noinspection JSCheckFunctionSignatures
Vue.component('tt-button', {
//language=Vue
template: `
<a v-if="href" :href="href" class="btn" :class="buttonClasses" @click="handleClick">
<template v-if="loading">
<span class="spinner"></span>
</template>
<template v-else>
<i v-if="icon" :class="icon"></i>
{{text}}
</template>
</a>
<button v-else @click="handleClick" class="btn" :class="buttonClasses" :disabled="loading">
<template v-if="loading">
<span class="spinner"></span>
</template>
<template v-else>
<i v-if="icon" :class="icon"></i>
{{text}}
</template>
</button>
<component :is="href ? 'a' : 'button'"
:href="href"
:disabled="!href && loading"
:class="buttonClasses"
class="btn"
@click="handleClick">
<span v-if="loading" class="spinner"></span>
<template v-else>
<i v-if="icon" :class="icon"></i>
{{ text }}
</template>
</component>
`,
props: {
sm: {type: Boolean, default: false},
@@ -32,26 +25,20 @@ Vue.component('tt-button', {
},
computed: {
buttonClasses() {
const classes = {
'btn-sm': this.sm,
'btn-loading': this.loading
}
if (this.additionalClass) {
this.additionalClass.split(' ').forEach(className => {
classes[className] = true
})
}
return classes
const classes = [];
if (this.sm) classes.push('btn-sm');
if (this.loading) classes.push('btn-loading');
if (this.additionalClass) classes.push(...this.additionalClass.split(' '));
return classes;
}
},
methods: {
handleClick(event) {
if (this.loading) return event.preventDefault();
if (typeof this.confirmText === 'string' && !confirm(this.confirmText)) return event.preventDefault();
this.$emit('click', event)
if (this.loading || (this.confirmText && !confirm(this.confirmText))) {
event.preventDefault();
return;
}
this.$emit('click', event);
}
}
})
});