Vue.js 服务器端呈现:文档未定义

Vue.js Server Side Rendering: document is not defined

我正在使用一个使用 documentwindow 的包。我想让我的网站在不更改太多代码的情况下具有服务器端渲染。对于 window is not defined,我使用 window-or-global (https://www.npmjs.com/package/window-or-global),它解决了我的问题。

可是,说到document,我倒是没觉得有什么用。我的想法是尝试找出服务器或客户端何时呈现。我只会在客户端渲染时执行带有 document 的代码。有什么办法吗?

P/S:我正在使用 Vue.js 2.0。我使用的包是 fine-uploader (https://www.npmjs.com/package/fine-uploader)

我在新项目中也使用了Vue服务端渲染,针对此类问题我做的是检查我是在浏览器环境中还是在服务器环境中使用:

if (typeof window !== 'undefined') {
    // We are in the browser
}

您可以使用

const Vue = require('vue');
Vue.prototype.$isServer

或从组件内部

this.$isServer