API nuxt.renderAndGetWindow

API: nuxt.renderAndGetWindow(url, options)

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)
  })