Я использую Firefox 56 с dom.moduleScripts.enabled
установленным в true. Это позволяет мне работать с родными модулями ES6.
У меня есть компонент vue2, который имеет определенный метод:
import StorageZonesAjaxMethods from '../../ajax/storage-zones.js';
....
methods: {
updateList()
{
//console.log(StorageZonesAjaxMethods);
StorageZonesAjaxMethods.getList();//function(response) { this.list = response.data.payload;});
},
},
где класс с методами:
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);
}
Я получаю сообщение об ошибке "TypeError: (intermediate value).getList is not a function"
в firefx ", но console.log показывает, что это так, но по какой-то причине внутри конструктора. Что происходит?
Никогда не используйте new class { … }
!
И не дефолт-экспорт class
с использованием только static
методов. Упростить
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';
Извлеченный урок - не кодируйте усталыми глазами. export default new class StorageZonesAjaxMethods
в классе не должен иметь new
там