DEV Community

Discussion on: Functional components in Vue.js (2.x)

Collapse
 
adamorlowskipoland profile image
Adam

It has been a while but maybe someone will benefit from it:
You don't have to declare your methods in a methods property.

<script>
export default {
  name: 'DisplayDate',
  props: {
    date: {
      type: String,
      required: true,
    },
  },
  format(date) {
    return new Date(date).toLocaleString()
  },
}
</script>
Enter fullscreen mode Exit fullscreen mode

and then in a template

<template functional>
  <span>{{ $options.format(date) }}</span>
</template>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
vhoyer profile image
Vinícius Hoyer

Yeah, you are right, at the time I hadn't realize that yet. Thanks for your comment :D