All Collections
EmbedReviews
Display reviews
Applications
How to Embed Code in a Vue Application
How to Embed Code in a Vue Application

Steps on how you can embed the EmbedSocial Widget Code in a Vue Application.

Didi avatar
Written by Didi
Updated over a week ago

In Vue applications, there are two options when embedding custom HTML/javascript code:

  • Composition API

  • Options API

First, you will need to copy your widget code:

Copying the code

After you have copied the code, you will need to separate the HTML from the javascript, for example:

EmdedSocial widget code:

<div class="embedsocial-hashtag" data-ref="a4f74f50d0016f41895f78a3141a52b07c6933aa"></div> <script> (function(d, s, id) { var js; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "https://embedsocial.com/cdn/ht.js"; d.getElementsByTagName("head")[0].appendChild(js); }(document, "script", "EmbedSocialHashtagScript")); </script>

HTML

<div class="embedsocial-hashtag" data-ref="a4f74f50d0016f41895f78a3141a52b07c6933aa"></div

CSS

(function(d, s, id) { var js; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "https://embedsocial.com/cdn/ht.js"; d.getElementsByTagName("head")[0].appendChild(js); }(document, "script", "EmbedSocialHashtagScript")); 

1. Embedding the widget through the Options API

To embed the EmbedSocial widget code in a Vue application that uses the Options API, please follow the steps below:

First, head over to your Vue application and create a new component in your components directory:

Paste the EmbedSocial widget HTML code inside the <template> tags:

Paste the EmbedSocial widget javascript code inside the created lifecycle hook:

Now after you’ve created the EmbedSocial widget component, you just need to import the component and display it on your website.

Open the file/page where you want to display the widget and import the component, in this case, we are importing it in App.vue:

Here are the results from this code and using Options API

2. Composition API

The Composition API is an addition to the Vue framework created to address the limitations of the Options API used in Vue2.

In order to embed your widget code in a Vue application that uses the Composition API, you will need to follow the steps below:

First, head over to your Vue application and create a new component in your components directory:

Next, paste the EmbedSocial widget HTML code inside the <template> tags:

Then you will need to import onCreated function from Vue, and paste the EmbedSocial widget javascript code inside the onCreated function:

By following the steps above, you’ve created the EmbedSocial widget component, we have to import the component and display it on your website.

Open the file/page where you want to display your widget and import the component, in this case, we are importing it in App.vue:

Once this is done, your widget will be displayed on your website.

That's it.

If you have any questions, click the bottom right chat icon to talk with our customer success team or send us an email at support@embedsocial.com

We're here for you 🙏

Did this answer your question?