VueJS 多个混合

ses*_*360 4 javascript vue.js

我的脚本中有一个错误,我不知道要修复。我想导入我创建的多个 mixin。

import GoogleMaps from '../mixins/GoogleMaps.js';
import MFApi from '../mixins/MFApi.js';

    export default {
        template: require('../templates/map.html'),
        mixins: [GoogleMaps, MFApi],
(...)
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。如果 mixins 变量不止一个,我该如何正确设置它?

一旦我将新的 mixin 添加到变量中,第一个就不再被识别。

The*_*lni 5

也许你有这样的案例。如果您导出命名模块,而不仅仅是默认情况下,那么您需要使用花括号导入它。

在我的 mixin 文件夹中,我有“regExpressions.js”文件:

export const convertImage = {
  methods: {
   ...your methods here
  }
}
Run Code Online (Sandbox Code Playgroud)

和“truncateString.js”文件:

export default {
  methods: {
   ... your code here
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的组件中,我导入了我的 mixin。

import { convertImage } from "@/mixins/regExpressions";
import truncateString from "@/mixins/truncateString";

mixins: [truncateString, convertImage]
Run Code Online (Sandbox Code Playgroud)