简体   繁体   English

在Vue组件中导入助手类

[英]Import Helper Class in Vue Component

I'd like to import a helper class rather than inlining the logic inside my component. 我想导入一个辅助类而不是内联组件中的逻辑。 I get the following error: 我收到以下错误:

http://eslint.org/docs/rules/no-unused-vars  'NavbarService' is defined but never used

/services/NavbarService.js /services/NavbarService.js

class NavbarService {
  constructor (init) {
    this.init = init;
  }

  static applications () {
    return [
      { name: 'Administration' },
      { name: 'Standard' }
    ];
  }

  static views () {
    return [
      { name: 'Providers', path: '/providers' },
      { name: 'Authorities', path: '/authorities' },
      { name: 'Services', path: '/services' },
      { name: 'Codes', path: '/codes' }
    ];
  }
}

/components/Navbar.vue /components/Navbar.vue

import NavbarService from '../services/NavbarService.js';

export default {
  data () {
    return {
      versionIsVisible: false,
      version: '2.0.0',
      applications: NavbarService.applications(),
      views: NavbarService.views()
    };
  },

  methods: {
    showApplications: function () {
      this.applications = NavbarService.applications();
      this.views = [];

      return;
    }
  }
};

Following Roy J's suggestion, I changed /services/NavbarService.js to: 根据Roy J的建议,我将/services/NavbarService.js更改为:

export default {
  applications: function () {
    return [
      { name: 'Administration' },
      { name: 'Standard' }
    ];
  },

  views: function () {
    return [
      { name: 'Providers', path: '/providers' },
      { name: 'Authorities', path: '/authorities' },
      { name: 'Services', path: '/services' },
      { name: 'Codes', path: '/codes' }
    ];
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM