修复:统一使用 window.Alpine 防止 defer 加载时 Alpine 未定义报错

This commit is contained in:
2026-03-15 17:05:33 +08:00
parent 51aa3931b9
commit c2293f96cb

View File

@@ -55,9 +55,16 @@
// 剥除可能从消息内容带入的装饰括号(如 【username】 → username
username = String(username).replace(/^[\u3010\[【\s]+|[\u3011\]】\s]+$/g, '').trim();
if (!username) return;
// Alpine.js 使用 defer 异步加载,检查是否已完成初始化
if (!window.Alpine) {
console.warn('[openUserCard] Alpine.js 尚未初始化,请稍后再试');
return;
}
const el = document.getElementById('user-modal-container');
if (el) {
const data = Alpine.$data(el);
const data = window.Alpine.$data(el);
if (data) data.fetchUser(username);
}
}
@@ -200,7 +207,7 @@
// 打开专属离婚确认弹窗
const modal = document.getElementById('divorce-confirm-modal');
if (modal && window.Alpine) {
Alpine.$data(modal).open(marriageId, divorceConfig);
window.Alpine.$data(modal).open(marriageId, divorceConfig);
}
},
@@ -1199,11 +1206,10 @@
*/
function openRewardModal(username) {
const el = document.getElementById('reward-modal-container');
if (el) {
const data = Alpine.$data(el);
if (data) {
data.open(username);
}
if (!window.Alpine || !el) return;
const data = window.Alpine.$data(el);
if (data) {
data.open(username);
}
}
</script>