2017-09-26 57 views
0

请看下面的代码面对错误窗口没有被定义[COLSED]

render() { 

    const post = this.props.post; 

    let postClass = "posts-item"; 
    if (post.sticky) postClass += " posts-sticky"; 

    // ⭐ custom code starts here ⭐ 
    if (post.color) { 
     postClass += " post-"+post.color; 
    } 
    // ⭐ custom code ends here ⭐ 
    const currentUrl = window ? window.location.href : undefined; 
    ....... 
    ........ 
} 

在这行代码const currentUrl = window ? window.location.href : undefined;正在生成follwoing错误

url:/
{ [ReferenceError: window is not defined] queryErrors: [ [Circular] ] } 

如何解决这一问题?

+0

无法重现错误修复了这个问题。你可以登录窗口,看看你的渲染方法打印什么? –

+0

console.log(窗口)给窗口对象 –

+0

那么为什么它给窗口的错误没有定义。你可以将你的项目发布到某处进行调试吗?就像github或jsfiddle –

回答

0

我已经通过下面的代码

let currentUrl; 
    if(Meteor.isClient) 
    currentUrl = window ? window.location.href : undefined;