2016-09-19 77 views
3

我想導入一個助手類而不是內聯組件內部的邏輯。我得到以下錯誤: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

繼羅伊·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' } 
    ]; 
    } 
};