修复:礼物 JSON 数据破坏 Alpine.js x-data 属性解析

- 将 Js::from() 移到 script 标签输出为全局变量
- Alpine 组件通过 window.__gifts 引用,避免双引号冲突
This commit is contained in:
2026-02-27 01:04:03 +08:00
parent c5cc55fc84
commit 2e184832cb
@@ -63,6 +63,11 @@
{{-- ═══════════ 用户名片弹窗 (Alpine.js) ═══════════ --}}
@php $gifts = \App\Models\Gift::activeList(); @endphp
<script>
// 礼物数据注入(避免 JSON 破坏 x-data 属性解析)
window.__gifts = {!! Js::from($gifts) !!};
window.__defaultGiftId = {{ $gifts->first()?->id ?? 0 }};
</script>
<div id="user-modal-container" x-data="{
showUserModal: false,
userInfo: {},
@@ -72,8 +77,8 @@
whisperList: [],
showAnnounce: false,
announceText: '',
gifts: {{ Js::from($gifts) }},
selectedGiftId: {{ $gifts->first()?->id ?? 0 }},
gifts: window.__gifts || [],
selectedGiftId: window.__defaultGiftId || 0,
giftCount: 1,
sendingGift: false,