如果pages/index.astro我嘗試
---
console.log(location.href)
---
然后我得到
![從 AstroJS [plugin:astro] 中的頁面未定義位置](https://i.stack.imgur.com/1UtMx.png)
文字錯誤:
[plugin:astro] 位置未定義
檔案中的匯出陳述句
.astro無法訪問區域變數宣告,只能訪問匯入的值。
如何從 AstroJs 頁面訪問或匯入位置?
uj5u.com熱心網友回復:
location是一個瀏覽器全域。它在 Node 中不存在,您的 Astro 站點將在其中構建。
改為使用Astro.url.href,可在此處找到其檔案:https ://docs.astro.build/en/reference/api-reference/#astrourl
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/522732.html
上一篇:解決查詢結構問題
