Skip to content

Instantly share code, notes, and snippets.

@syuji-higa
Created December 25, 2019 06:56
Show Gist options
  • Save syuji-higa/966e377e0297763896ae79afbc42b586 to your computer and use it in GitHub Desktop.
Save syuji-higa/966e377e0297763896ae79afbc42b586 to your computer and use it in GitHub Desktop.
Vue.js - SFC generic components
<template>
<component
:is="tag"
class="small-button-component"
:disabled="isDisabled"
v-bind="attrs"
v-on="$listeners"
>
{{ text }}
</component>
</template>
<script>
export default {
inheritAttrs: false,
props: {
tag: {
type: String, // 'button' | 'a' | 'nuxt-link'
default: 'button'
},
text: {
type: String,
required: true
},
isDisabled: {
type: Boolean,
default: false
}
},
computed: {
attrs() {
const obj = {}
if (this.tag === 'button') {
obj.type = 'button'
}
return Object.assign(obj, this.$attrs)
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment