在 Nuxt 模板中使用 Mixin

F4l*_*0ut 3 javascript vue.js nuxt.js

我正在尝试在模板中调用 mixin 函数。Vue 文档说 mixin 和组件已合并,但我无法调用该函数。

getImage 不是函数

混入

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

成分

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

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

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

<style scoped></style>
Run Code Online (Sandbox Code Playgroud)

Mic*_*evý 6

更改mixin: { imageMixin }mixins: [imageMixin]