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