试图将其他人的代码示例改编为我的项目,并且在导入文件后对如何调用函数有点困惑。
控制台操作系统日志记录错误Uncaught TypeError: loadData.markets is not a function
我试图markets()
在导入后从此文件中调用该函数:
/* eslint-disable */
var ccxt = require('ccxt')
export default {
markets: async function () {
var exchanges = {
"bittrex": {},
"bitfinex": {},
}
let ids = ccxt.exchanges.filter (id => id in exchanges)
await Promise.all (ids.map (async id => {
// console.log (exchanges[id])
// // instantiate the exchange
let exchange = new ccxt[id] (exchanges[id])
// console.log (exchange.id, exchange.apiKey)
exchanges[id] = exchange
// load markets
var markets = await exchange.loadMarkets ()
console.log (exchange.id, 'loaded')
exchanges[exchange.id].markets = markets
return exchange
}))
// when all of them are ready, do your other things
console.log ('Loaded exchanges:', ids.join (', '))
return exchanges
//console.log(exchanges.bitfinex.markets)
}
}
这是混合:
loadDataMixin.js
/* eslint-disable */
const ccxt = require('ccxt')
const loadData = require('../../lib/loadData')
export default {
data() {
return {
exchangeList: ccxt.exchanges,
markets: {}
}
},
methods: {
listExchanges() {
console.log(this.exchangeList)
},
loadMarkets() {
this.markets = loadData.markets()
}
}
}
这是组件:
<template>
<div id="app" class="container">
<div>
<h1>Arb Bot</h1>
<button type="button" class="btn btn-primary" v-on:click="loadMarkets()">Load data</button>
</div>
</div>
</template>
<script>
/* eslint-disable */
import loadDataMixin from './components/mixins/loadDataMixin'
const ccxt = require('ccxt')
export default {
name: 'App',
mixins: [loadDataMixin]
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
margin-top: 60px;
}
.main-table {
margin-top: 20px;
}
</style>
如何从 loadData.js 调用markets() 函数?