Vuejs - use function getProperties on exported class

时间:2018-07-25 05:18:41

标签: javascript ecmascript-6 vuejs2

I have a source module:

import _ from 'underscore'
import {Observable} from 'rxjs'

export default function (rxfb) {
  return {
    getProperties () {
      return rxfb.sources.user.getUser()
        .switchMap(({properties}) =>
          properties
            ? Observable.combineLatest(_(properties).map((property, propertyId) =>
              this.getProperty(propertyId).map(property => ({propertyId, ...property}))))
            : Observable.from([{}]))
    }
  }
}

I need to access it from another section so I am importing it:

import myProperties from '../../sources/properties'

Then I try:

console.log(myProperties.getProperties())

but it does not work, what is the proper way to get access to this method?

1 个答案:

答案 0 :(得分:1)

您正在导出 function ,但是您像 Object 一样使用它!

似乎您必须像这样使用它(调用函数):

import myProperties from '../../sources/properties'
console.log(myProperties().getProperties())