修复:Alpine.js userInfo.position_history 初始 undefined 导致 length 报错
- userInfo 初始值加 position_history: [],防止挂载时 undefined.length - x-text 和 x-if 里加可选链 ?.length ?? 0 双重兜底
This commit is contained in:
@@ -77,7 +77,9 @@
|
||||
function userCardComponent() {
|
||||
return {
|
||||
showUserModal: false,
|
||||
userInfo: {},
|
||||
userInfo: {
|
||||
position_history: []
|
||||
},
|
||||
isMuting: false,
|
||||
muteDuration: 5,
|
||||
showWhispers: false,
|
||||
@@ -490,7 +492,7 @@
|
||||
cursor: pointer; font-size: 11px; font-weight: bold; color: #7c3aed;
|
||||
margin-bottom: 4px; user-select: none;">
|
||||
<span>🎖️ 职务履历 <span style="font-weight: normal; font-size: 10px; color: #9ca3af;"
|
||||
x-text="'(' + userInfo.position_history.length + ' 条)'"></span></span>
|
||||
x-text="'(' + (userInfo.position_history?.length ?? 0) + ' 条)'"></span></span>
|
||||
<span x-text="showPositionHistory ? '▲' : '▼'" style="font-size: 10px; opacity:0.5;"></span>
|
||||
</div>
|
||||
{{-- 折叠内容 --}}
|
||||
@@ -504,7 +506,7 @@
|
||||
:style="h.is_active ? 'background: #7c3aed; box-shadow: 0 0 0 3px #ede9fe;' :
|
||||
'background: #d1d5db;'">
|
||||
</div>
|
||||
<template x-if="idx < userInfo.position_history.length - 1">
|
||||
<template x-if="idx < (userInfo.position_history?.length ?? 0) - 1">
|
||||
<div style="width: 1px; flex: 1; background: #e5e7eb; margin-top: 2px;"></div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user