如何在axios中使用电子打印功能

时间:2019-07-05 12:20:26

标签: javascript reactjs electron axios

我想在axios中使用electron-printer然后起作用。在then函数中如何访问打印机对象?

import printer from 'electron-print';

axios
    .get(`${URL}`)
    .then(response => {
        printer.print('test');
    })
TypeError: BrowserWindow is not a constructor

import {printer} from 'electron-print';

axios
    .get(`${URL}`)
    .then(response => {
        // printer is undefined
        printer.print('test');
    })

1 个答案:

答案 0 :(得分:0)

我认为您是import的自由主义者,就像电子印刷文档中所见,它是require

正如我在评论中告诉您的,您可以尝试复制/粘贴此内容吗?

import {print} from 'electron-print';

axios
    .get(`${URL}`)
    .then(response => print('test'));

因为您错了:

import {printer} ...
    ...
    print('test'));