1.安装npm环境
npm install -g cnpm -registry=https://registry.
2.安装全局jsdom
npm i jsdom -g
3.js代码顶部加入:
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
window = dom.window;
document = window.document;
XMLHttpRequest = window.XMLHttpRequest;