'Vue mixins unresolved function or method in template

I created a global function file:

module.exports = {
  methods: {
    t(key, replace = {}) {
      return 'test';
    }
  }
}

And I imported that to app with:

.mixin(require('./base'))

And this method works, but in my IDE (PhpStorm) is displaying error Unresolved function or method t in Vue files. How to display hints for functions like that?



Solution 1:[1]

Yo need to use as named or default export.

export const myMixin = {
  methods: {
    t(key, replace = {}) {
      return 'test';
    }
  }
}

Then import like

import Vue from 'vue';
import { myMixin } from '..../myMixin.js';

Vue.mixin(myMixin);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 power-cut