API nuxt.renderAndGetWindow
nuxt.renderAndGetWindow(url, options = {})
类型: Function
参数: String
virtualConsole: Boolean (认值:true)
String: 待渲染的 URL 路径
可选, Object: options
返回值: Promise
Promise 最终返回的值: window
渲染指定url并对应的window对象。
这个只用于测试目的。
要使用这个,需要先安装 jsdom:
npm install --save-dev jsdom
例如:
const Nuxt = require('nuxt') const nuxt = new Nuxt() nuxt.renderAndGetWindow('http://localhost:3000') .then((window) => { // 文档 console.log(window.document.title) })