admin管理员组文章数量:1356548
I am using a package which uses document
and window
. I want to make my website have server-side rendering without changing too much code. For window is not defined
, I use window-or-global
() and it solves my problem.
However, when it es to document
, I actually don't find anything useful. My idea is try to find out when the server or the client is rendering. I will only execute the code with document
when the client is rendering. Is there any way to do that?
P/S: I am using Vue.js 2.0. The package I am using is fine-uploader ()
I am using a package which uses document
and window
. I want to make my website have server-side rendering without changing too much code. For window is not defined
, I use window-or-global
(https://www.npmjs./package/window-or-global) and it solves my problem.
However, when it es to document
, I actually don't find anything useful. My idea is try to find out when the server or the client is rendering. I will only execute the code with document
when the client is rendering. Is there any way to do that?
P/S: I am using Vue.js 2.0. The package I am using is fine-uploader (https://www.npmjs./package/fine-uploader)
Share Improve this question edited Dec 21, 2016 at 4:57 Mahmud Adam 3,5798 gold badges37 silver badges54 bronze badges asked Dec 21, 2016 at 4:49 pexea12pexea12 1,2092 gold badges19 silver badges36 bronze badges2 Answers
Reset to default 4I'm also using Vue Server Side rendering in a new project, and what I do for this kind of problem is that I check if I am in the browser environment or in the server one using:
if (typeof window !== 'undefined') {
// We are in the browser
}
You can use
const Vue = require('vue');
Vue.prototype.$isServer
or from within a ponent
this.$isServer
本文标签: javascriptVuejs Server Side Rendering document is not definedStack Overflow
版权声明:本文标题:javascript - Vue.js Server Side Rendering: document is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743997228a2573215.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论