首页 > 解决方案 > 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>

标签: javascriptvue.jsnuxt.js

解决方案


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


推荐阅读