首页 > 教程
Astro 添加 Waline 评论组件
- 2025-04-07
- 1305 ℃
Astro 在使用视图过渡路由时,在跳转路由时,会导致 JS 文件只有在第一次进入页面时生效,所以 Astro 在使用视图过渡路由下 Waline 时无法正常使用的,我是单独写了一个评论组件,对 Waline 进行动态加载,然后在需要评论的页面引入的。
创建 Waline 评论组件
# 安装依赖 npm i @waline/client
<!-- Comment.astro -->
<section class="vh-comment"></section>
<script>
// 服务地址 URL
const WalineServerURL = "";
// 评论组件 dom
const commentDOM = ".vh-comment";
document.addEventListener("astro:page-load", async () => {
if (!document.querySelector(commentDOM) || !WalineServerURL) return;
import("@waline/client/waline.css");
import("@waline/client/waline-meta.css");
const { init } = await import("@waline/client");
init({ el: commentDOM, serverURL: WalineServerURL });
});
</script>使用 Waline 评论组件
<!-- Article.astro --> --- import Comment from '@/components/Comment.astro'; --- <!-- 引入评论组件 --> <Comment />
相关内容
PHP简易汉字验证码
Coze 扣子 - 字节出品...
(PHP)Redis Hash(哈希)操作
Excel文件比较器
splice变相跳出forEach循环
微信小程序调用摄像头实...
Duplicate Cleaner Pro...
微信设置电子监护人,杜...
-
(PHP)Redis Hash(哈希)操作
2025-04-07 1211
-
为什么你家装的千兆网还没别人的百兆网流畅呢
2025-06-25 1227
-
下载的漫画怎么看,一招让OneDrive支持WebDAV
2025-04-27 2224
-
微信拍照模糊调用手机相机拍照更清晰
2025-06-22 1311
-
JS压缩图片并保留图片元信息
2025-04-07 972
-
微信设置电子监护人,杜绝渣男
2025-06-22 1427
-
批量重命名文件,怎样快速去除括号?去掉空格!
2021-10-29 1687
-
很上档次别具一格的代码注释方式
2025-04-07 1179
-
骚扰电话API接口 开源
2025-04-07 1117
-
mysql数据库优化
2021-07-27 898
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


进入有缘空间
点击分享文章