AddThisIndex.vue 866 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <div
  3. v-bind="$attrs"
  4. class="addthis_inline_share_toolbox"
  5. />
  6. </template>
  7. <script>
  8. export default {
  9. name: "AddThis",
  10. props: {
  11. publicId: {
  12. type: String,
  13. required: true
  14. },
  15. cdn: {
  16. type: String,
  17. default: '//s7.addthis.com/js/300/addthis_widget.js'
  18. },
  19. async: {
  20. type: Boolean,
  21. required: false
  22. }
  23. },
  24. mounted() {
  25. if (document.getElementById('addthis-share') !== null) {
  26. return window.addthis && window.addthis.layers && window.addthis.layers.refresh();
  27. }
  28. const el = document.createElement('script');
  29. el.setAttribute('id', 'addthis-share');
  30. el.setAttribute('src', `${this.cdn}#pubid=${this.publicId}`);
  31. this.async && el.setAttribute('async', true);
  32. document.body.appendChild(el);
  33. }
  34. }
  35. </script>