首页 > 教程
Astro 添加 Waline 评论组件
- 2025-04-07
- 1526 ℃
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 微信公众号接入支付宝支付
原型继承和 Class 继承
使用电脑一定要学会的20...
人工智能:探索未知领域...
微信小程序调用摄像头实...
微信拍照模糊调用手机相...
怀疑对象出轨,学会这两...
-
易支付对接微信商户完整流程
2024-02-06 4538
-
加菲猫令人喷饭的经典台词(中英对照版)
2025-03-03 1386
-
可免费使用的网站CDN加速服务
2025-04-07 1281
-
正则表达式语法规则
2025-01-08 1721
-
splice变相跳出forEach循环
2025-04-07 1205
-
为什么你家装的千兆网还没别人的百兆网流畅呢
2025-06-25 1456
-
PHP超级Ping API接口 源码
2025-04-07 1379
-
2024年排名前5位的潜在云存储服务
2024-04-24 1675
-
PHP基本简单实用函数
2025-04-07 975
-
测试了一堆远程控制工具,发现最好用的原来是它
2025-04-27 1358
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


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