nuxt.renderAndGetWindow(url, options = {})

  • 类型: Function
  • 参数: String
    • String: 待渲染的 URL 路径
    • 可选Object: options
      • virtualConsole: Boolean (默认值:true)
  • 返回值: Promise
    • Promise 最终返回的值: window

渲染指定url并获取对应的window对象。

这个方法只用于 测试目的

要使用这个方法,需要先安装 jsdom

  1. npm install --save-dev jsdom

例如:

  1. const Nuxt = require('nuxt')
  2. const nuxt = new Nuxt()
  3. nuxt.renderAndGetWindow('http://localhost:3000')
  4. .then((window) => {
  5. // 显示文档标题
  6. console.log(window.document.title)
  7. })