Why I use vue-class-component

Readable class rather than an odd JS Object

Image for post
Image for post

vue-class-component

Readability

export default {
//scoped variables in this component
data () {
return {
message: 'Hello'
}
},
// observed variables (by function)
computed: {
reversedMessage () {
return this.message.split('').reverse().join('')
}
},
// functions firing by template
methods: {
changeMessage () {
this.message = "Good bye"
}
},
// child components this component calls
components: { },
// variables passed from parent template
props: { },

// Lifecycle hooks
created () { },
mounted () { },
updated () { },
destroyed () { }
}
@Component({
components: { },
props: { },
})
export default class extends Vue {
// data
message = 'Hello'
// computed
get reverseMessage () {
return this.message.split('').reverse().join('')
}
// method
changeMessage () {
this.message = 'Good bye'
}
// Lifecycle hooks
created () { },
mounted () { },
updated () { },
destroyed () { }
}

TypeScript Friendly

To use vuex-class

@Component
export default class extends Vue {
@Action foobar
created () {
this.foobar();
}
}

Officially maintained

Downsides

When we may stop using vue-class-component

Hai-iro

A Japanese duo by a product designer and a software…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store