簡體   English   中英

在Vue組件中導入助手類

[英]Import Helper Class in Vue Component

我想導入一個輔助類而不是內聯組件中的邏輯。 我收到以下錯誤:

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

/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

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;
    }
  }
};

根據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