KMENTA / 开始 / 快速开始
快速开始
把评论区接到你自己的页面,只需要两步:放一个挂载点,再引入一段脚本。样式自动注入,服务器地址自动识别。
最简接入(自动挂载)
<div id="kcomment"></div> <script src="https://api.example.com/widget/comment-widget.js"></script>
脚本加载后自动寻找 #kcomment 节点并挂载。挂载点缺省用 location.pathname 作为页面 Key,同一篇文章保持同一个评论区。
手动初始化
需要多个评论区、或想精确控制参数时,用 kcomment.init()。脚本仍以普通 script 引入,初始化代码放在其后即可。
<div id="kcomment"></div> <script src="/widget/comment-widget.js"></script> <script> kcomment.init({ el: '#kcomment', server: 'https://api.example.com', // 缺省自动识别 pageKey: '/post/hello-world', // 缺省用 location.pathname theme: 'teal' // 缺省 'default' }); </script>
属性配置(零 JS)
不想写初始化代码?直接在 script 标签上放属性即可,效果与 init() 参数一一对应。
<div id="kcomment"></div> <script src="https://api.example.com/widget/comment-widget.js" data-server="https://api.example.com" data-page-key="/post/42" data-theme="crimson" defer></script>