2016-09-19 13 views
3

コンポーネント内のロジックをインライン展開するのではなく、ヘルパークラスをインポートしたいと思います。ロイ・Jの提案に続きVueコンポーネントのヘルパークラスをインポートする

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

はこれまで、クラスをインスタンス化し、何もないか、それは純粋にヘルパー関数のコンテナですか? –

+0

純粋に容器。 – Donnie

+1

あなたはクラスを望んでいないと思います。あなたはそれを平易なものにできますか? –

答えて

3

:私は次のエラーを取得します、私は変更しました/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' } 
    ]; 
    } 
}; 
関連する問題