首页 > 教程
Astro 添加 Waline 评论组件
- 2025-04-07
- 1340 ℃
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密码加密方法
免费下载PPT模板的网站来了
云计算在电子商务和零售...
为什么你的AI助手总是答...
电视源分享 - 在线看央...
NodeJs文本相似度去重脚本
这些搜索方法可以助你事...
竞品分析过后就是抄吗?
-
微信最快的搜索方法 - 输入#号加内容
2025-06-22 1269
-
微信公众号支付(JSAPI)对接方法,详细教程
2024-02-06 1481
-
为什么我国没有ChatGPT那样强大的AI智能系统
2024-03-16 1386
-
你真的知道怎么搜索网盘资源吗
2025-03-10 1674
-
下载B站视频,知道这些方法就够了
2025-03-10 1404
-
mysql数据库优化
2021-07-27 935
-
市面常用浏览器锐评,从优秀到垃圾
2025-09-27 1126
-
微信小程序登陆封装
2025-04-07 1044
-
简单实用的电脑技巧,提高您的工作效率!
2021-10-27 882
-
手撸call apply bind
2025-04-07 881
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


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