使用jsdom
在js的头加上
const canvas = require('canvas'); const jsdom = require("jsdom"); const {JSDOM} = jsdom; const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p >`); window = dom.window; document = window.document;
使用jsdom
在js的头加上
const canvas = require('canvas'); const jsdom = require("jsdom"); const {JSDOM} = jsdom; const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p >`); window = dom.window; document = window.document;