NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

hero.vue 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template lang="pug">
  2. .hero.f-col(v-if="showHero")
  3. .hero--video(v-if="heroType === 'video'")
  4. iframe(
  5. v-if="isPlaying"
  6. :src="`https://www.youtube.com/embed/${heroIdFromUrl}?autoplay=1`"
  7. frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope"
  8. allowfullscreen
  9. ).embedded
  10. .blank.f-col(v-else)
  11. h3(v-if="heroText") {{ heroText }}
  12. button(v-if="showPlaybutton" @click="isPlaying = true") play
  13. .hero--image(v-else)
  14. img(:src="showHero" alt="hero image")
  15. </template>
  16. <script>
  17. import { mapState } from 'vuex'
  18. export default {
  19. data() {
  20. return {
  21. heroHeight: 0,
  22. isPlaying: false
  23. }
  24. },
  25. computed: {
  26. ...mapState({
  27. showHero: state => state.hero.url,
  28. heroText: state => state.hero.text,
  29. heroType: state => state.hero.type,
  30. showPlaybutton: state => state.hero.playbutton,
  31. }),
  32. heroIdFromUrl() {
  33. console.log()
  34. const url = this.showHero.split('/')
  35. return url.pop()
  36. }
  37. },
  38. methods: {
  39. onResize() {
  40. this.heroHeight = this.$el.offsetWidth / 1.8
  41. }
  42. },
  43. mounted() {
  44. this.heroHeight = this.$el.offsetWidth / 1.8
  45. this.$nextTick(() => { window.addEventListener('resize', this.onResize) })
  46. },
  47. watch: {
  48. $route() {
  49. console.log('remounting hero')
  50. console.log(this.$store)
  51. // Clear the hero between pages
  52. this.$store.commit('CLEAR_HERO')
  53. },
  54. heroHeight() {
  55. if(!this.showHero) return
  56. Object.assign(this.$el.style, {height: this.heroHeight + 'px'})
  57. }
  58. },
  59. beforeUnmount() {
  60. window.removeEventListener('resize', this.onResize)
  61. },
  62. }
  63. </script>
  64. <style lang="postcss">
  65. .hero
  66. background-color: rebeccapurple
  67. min-height: 35%
  68. width: 100%
  69. &--image
  70. > img
  71. max-width: 100%
  72. .embedded
  73. height: 100%
  74. width: 100%
  75. </style>