nuxt.renderAndGetWindow(url, options)
从 Nuxt 应用程序的给定 URL 获取 window 对象。
-
类型:
Function -
参数:
String-
String:要渲染的 URL -
可选
Object:选项
-
virtualConsole:
Boolean(默认:true)
-
-
返回值:
Promise-
返回值:
window
-
返回值:
此方法仅用于测试目的。
使用此函数需要安装 jsdom:
npm install --save-dev jsdom
示例:
const { loadNuxt } = require('nuxt')
async function init() {
// 假设已构建好项目
const nuxt = await loadNuxt({ for: 'start' })
await nuxt.listen(3000)
const window = await nuxt.renderAndGetWindow('http://localhost:3000')
// 打印 head `<title>`
console.log(window.document.title)
nuxt.close()
}
init()
接下来?
查看组件词汇表 。
Edit this page on GitHub
Updated at Tue, Apr 14, 2026