VideoPreview.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <a href="#" @click.prevent="open">
  3. <img :src="img" :alt="title" style="border-radius: 6px;">
  4. </a>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. title: {
  10. type: String,
  11. default: "Play Vuex Explained Visually Video"
  12. },
  13. img: {
  14. type: String,
  15. default: "/vuex-explained-visually.png"
  16. },
  17. url: {
  18. type: String,
  19. default: "https://player.vimeo.com/video/297515936?autoplay=1"
  20. }
  21. },
  22. methods: {
  23. open() {
  24. // dropped v-if/v-else way to fix autoplay issue on Chrome
  25. // https://github.com/vuejs/vuex/pull/1453#issuecomment-441507095
  26. const { $el, url } = this;
  27. if (!$el || !$el.parentNode) {
  28. return;
  29. }
  30. const attrs = {
  31. width: 640,
  32. height: 360,
  33. frameborder: 0,
  34. src: url,
  35. webkitallowfullscreen: true,
  36. mozallowfullscreen: true,
  37. allowfullscreen: true
  38. };
  39. const video = document.createElement('iframe');
  40. for (const name in attrs) {
  41. video.setAttribute(name, attrs[name]);
  42. }
  43. $el.parentNode.replaceChild(video, $el);
  44. }
  45. }
  46. }
  47. </script>