Skip to main content

VueJS Component

Loading an external script inside a Vue app takes some care: you have to load it once, wait for it, and keep it in sync with your components. The announcekit-vue component does this for you and adds the AnnounceKit widget to your app.

Step 1

Install the component from npm. The current version (3.x) is for Vue 3:
npm install announcekit-vue

For Vue 2, install the 2.x line instead:
npm install announcekit-vue@2

Step 2

Get the URL of the widget you want to include. You can find it in the widget’s install code, as the widget key, for example https://announcekit.app/widgets/v2/31nbbO.

Step 3 (Vue 3)

Register the plugin once, in your main file:

import { createApp } from "vue";
import AnnounceKit from "announcekit-vue";
import App from "./App.vue";

createApp(App).use(AnnounceKit).mount("#app");

Then use the component in any template:

<template>
  <nav>
    <ul>
      <li><a href="/home">Home</a></li>
      <li>
        <a href="#" class="ak-trigger">News</a>
        <AnnounceKit
          catchClick=".ak-trigger"
          widget="https://announcekit.app/widgets/v2/31nbbO" />
      </li>
    </ul>
  </nav>
</template>

Step 3 (Vue 2)

With announcekit-vue@2, import the component and register it locally:

<template>
  <nav>
    <ul>
      <li><a href="/home">Home</a></li>
      <li>
        <a href="#" class="ak-trigger">News</a>
        <AnnounceKit
          catchClick=".ak-trigger"
          widget="https://announcekit.app/widgets/v2/31nbbO" />
      </li>
    </ul>
  </nav>
</template>

<script>
import AnnounceKit from "announcekit-vue";
export default {
  name: "App",
  components: {
    AnnounceKit
  }
};
</script>

The catchClick property listens for clicks on the element you name and opens the widget. It is optional, and is most useful with Badge and Line widgets.

These are the properties the component accepts:

Property Description
widget The URL of the widget. You can copy it when you create or edit a widget in the dashboard.
widgetStyle CSS rules to fine-tune the position of the launcher. Styling docs
catchClick Element selector to catch clicks and open the widget.
floatWidget Set true if the widget is a Float widget.
embedWidget Set true if the widget is an Embed widget.
lang Language code, or “auto” to follow the browser. Language docs
boosters Set false to stop In-app Notifications (banners and pop-ups) from showing on this page.
user User properties (for user tracking)
data Segmentation data
onWidgetOpen Called when the widget is opened.
onWidgetClose Called when the widget is closed.
onWidgetResize Called when the widget is resized.
onWidgetUnread Called when unread post count of widget has been updated.

With a ref you can call open(), close(), unread() and instance() on the component.

Please follow our GitHub repo for further updates.
Resources:

Vue 3 Resources