[英]Meteor.user() Error: Uncaught TypeError: Cannot read property 'name' of null
我正在使用Meteor框架,當我嘗試將當前用戶的名稱返回給模板助手時,出現了此錯誤。
Template.user.userName = function (){
return Meteor.user().name;
}
<template name ="user">
{{userName}}
</template>
我不斷收到此錯誤:(錯誤:Uncaught TypeError:無法讀取null的屬性“名稱”)
但是,一切都可以從javascript控制台正常運行。
任何幫助將非常感激。
如果沒有用戶登錄, Meteor.user()
返回null。為了安全起見,您應該執行類似Meteor.user() ? Meteor.user().name : ''
Meteor.user() ? Meteor.user().name : ''
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.