2017-11-03 2 views
1

dom.moduleScripts.enabledをtrueに設定してFirefox 56を使用しています。これにより、ネイティブのES6モジュールで作業することができます。インポートしたES6モジュールから静的メソッドを呼び出そうとしています

Iが定義された方法を有するvue2成分を有する:私はfirefxにエラー"TypeError: (intermediate value).getList is not a function"を取得

export default new class StorageZonesAjaxMethods { 

    static getItem(id, then) 
    { 
     axios.get(`${Config.apiBaseUrl}/storage-zones/${id}`) 
      .then(response => then); 
    } 

    static getList(then) 
    { 
     alert('in get list'); 
     axios.get(`${Config.apiBaseUrl}/storage-zones`) 
      .then(response => then); 
    } 

、しかしにconsole.log:

メソッドを持つクラスがある
import StorageZonesAjaxMethods from '../../ajax/storage-zones.js'; 
.... 
methods: { 
     updateList() 
     { 
      //console.log(StorageZonesAjaxMethods); 
      StorageZonesAjaxMethods.getList();//function(response) { this.list = response.data.payload;}); 

     }, 
    }, 

表示されていますが、何らかの理由でコンストラクタ内にあります。どうしたの?

答えて

0

教訓 - 疲れた目でコード化しないでください。クラス内のexport default new class StorageZonesAjaxMethodsにはnewが含まれていてはなりません。

0

Never use new class { … }

およびdon't default-export a class with only static methodsのいずれかです。私は本当のコーディングの世界から来

export default { 
    getItem(id) { 
     return axios.get(`${Config.apiBaseUrl}/storage-zones/${id}`); 
    } 
    getList() { 
     alert('in get list'); 
     return axios.get(`${Config.apiBaseUrl}/storage-zones`); 
    } 
}; 

それとも、より良い両方のファイルを変更し、

export function getItem(id) { 
    return axios.get(`${Config.apiBaseUrl}/storage-zones/${id}`); 
} 
export function getList() { 
    alert('in get list'); 
    return axios.get(`${Config.apiBaseUrl}/storage-zones`); 
} 

import * as StorageZonesAjaxMethods from '../../ajax/storage-zones.js'; 
+0

を使用するに簡素化します。静的メソッドのクラスはコードの匂いではありません!私はオブジェクトをエクスポートすることだけを考えましたが、私はセメント的にグループ分けしたいと思います。なぜなら、それはクラスがあるからです。 – user3791372

+0

@ user3791372「実際のコーディングの世界」という言葉が何であるか分かりませんが、JSでは間違いなくコードの匂いです。コードを整理するためのクラスの使用はJava技術です。 JSには、このためのモジュールとオブジェクトが一流の市民として存在します。 – Bergi

関連する問題