Slider.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <!--Slider滑块组件-->
  2. <template>
  3. <div>
  4. <div v-for="item in sliderJson"
  5. :style="{
  6. position:'absolute',
  7. left:item.Left*bigScale+'px',
  8. top:item.Top*bigScale+'px',
  9. width:item.Width*bigScale + 'px',
  10. height:item.Height*bigScale + 'px',
  11. zIndex:item.ZIndex,
  12. display:item.IsVisibility ? 'block' : 'none',
  13. backgroundRepeat:'no-repeat',
  14. }"
  15. :ref="item.ID"
  16. >
  17. <div
  18. :style="{
  19. width:item.imgBgWidth*bigScale + 'px',
  20. height:item.imgBgHeight*bigScale + 'px',
  21. }"
  22. >
  23. <div
  24. :style="{
  25. width:item.imgSliderWidth*bigScale + 'px',
  26. height:item.imgSliderHeight*bigScale + 'px',
  27. backgroundImage:'url('+require(`../../../static/Data/${item.SliderIcon}`)+')',
  28. backgroundRepeat:'no-repeat',
  29. marginLeft:'40%',
  30. }"
  31. @click="clickBtn(item)"
  32. >
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. import {mapState} from 'vuex'
  40. import {getStaticFile} from "../../utils/tools"
  41. export default {
  42. data() {
  43. return {
  44. sliderJson:[],
  45. staticUrl:this.$store.state.staticUrl
  46. }
  47. },
  48. async beforeCreate() {
  49. this.sliderJson = await getStaticFile('EnitySlider.Data')
  50. },
  51. mounted() {
  52. // 设置背景图片
  53. const sliderArr = this.sliderJson
  54. const keyArr = Object.keys(this.$refs)
  55. keyArr.forEach((item,index) => {
  56. this.$refs[item][0].style.backgroundImage = sliderArr[index].BackIcon ? 'url('+`${this.staticUrl}/Data/${sliderArr[index].BackIcon}`+')' : null
  57. })
  58. },
  59. computed: {
  60. ...mapState(['bigScale']),
  61. }
  62. }
  63. </script>
  64. <style scoped>
  65. </style>