Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Mixin in template with Nuxt

I am trying to call the mixin function within the template. Vue documentation says mixin and the component are merged but i can't call the function.

getImage is not a function

Mixin

export default {
  data() {
    return {
      l: 2,
      output: 'webp'
    }
  },
  methods: {
    getImage() {
      return 'www.example.url'
    }
  }
}

Component

<template>
  <v-img :src="getImage()" />
</template>

<script>
import imageMixin from '~/mixins/image'

export default {
  name: 'New',
  mixin: { imageMixin }
}
</script>

<style scoped></style>
like image 534
F4ll0ut Avatar asked Oct 14 '25 20:10

F4ll0ut


1 Answers

Change mixin: { imageMixin } to mixins: [imageMixin]

like image 90
Michal Levý Avatar answered Oct 17 '25 10:10

Michal Levý



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!