置入框架

引入 Artalk

通过包管理工具引入 Artalk,推荐使用 pnpmopen in new window

pnpm add artalk

Vue

Vue 3 + TypeScript 例:

<template>
  <div class="artalk-comments"></div>
</template>

<script lang="ts">
import 'artalk/dist/Artalk.css'

import { defineComponent } from 'vue'
import Artalk from 'artalk'

export default defineComponent({
  mounted: () => {
    const artalk = new Artalk({
      el:        this.$el,
      pageKey:   `${location.pathname}`,
      pageTitle: `${document.title}`,
      server:    'http://localhost:8080',
      site:      'Artalk 的博客',
      // ...
    })
  }
})
</script>

React

import 'artalk/dist/Artalk.css'

import React, { createRef } from 'react'
import Artalk from 'artalk'

export default class Artalk extends React.Component {
  el = createRef()

  componentDidMount () {
    const artalk = new Artalk({
      el: this.el.current,
      pageKey:   `${location.pathname}`,
      pageTitle: `${document.title}`,
      server:    'http://localhost:8080',
      site:      'Artalk 的博客',
      // ...
    })
  }

  render () {
    return (
      <div ref={this.el} class="artalk-comments" />
    )
  }
}

Svelte

<script>
import 'artalk/dist/Artalk.css'
import Artalk from 'artalk'

let comments;

onMount(() => {
  new Artalk({
    el:        comments,
    pageKey:   `${location.pathname}`,
    pageTitle: `${document.title}`,
    server:    'http://localhost:8080',
    site:      'Artalk 的博客',
    // ...
  })
})
</script>

<div bind:this={comments} class="artalk-comments"></div>