当前位置:   article > 正文

vue中点击图片显示更多_vue3 :preview-src-list

vue3 :preview-src-list
  1. <template>
  2. <div class="demo-image__preview">
  3. <div class="box">
  4. <el-image
  5. v-for="(item, index) in srcList" :key="index"
  6. style="width: 100px; height: 100px"
  7. :src="srcList[index]"
  8. :preview-src-list="srcList"
  9. >
  10. </el-image>
  11. <p v-if="isShow" @click="up">显示更多</p>
  12. <p v-else @click="down"> 收起</p>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. isShow:true,
  21. srcList: [
  22. 'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg',
  23. 'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg',
  24. 'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg',
  25. 'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg',
  26. 'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg',
  27. ],
  28. sliceList:[]
  29. }
  30. },
  31. methods:{
  32. //展开
  33. up(){
  34. console.log(this.sliceList);
  35. this.sliceList.map(item=>{
  36. this.srcList.push(item)
  37. })
  38. this.isShow=false
  39. },
  40. down(){
  41. console.log(this.srcList);
  42. this.srcList=[...this.srcList.slice(0,3)]
  43. this.isShow=true
  44. }
  45. },
  46. mounted(){
  47. console.log(this.srcList);
  48. if(this.srcList.length>3){
  49. this.srcList.slice(2, this.srcList.length-1)
  50. console.log( this.srcList.slice(3, this.srcList.length));
  51. this.sliceList=[...this.srcList.slice(3, this.srcList.length)]
  52. console.log(this.srcList.slice(0,3));
  53. this.srcList=[...this.srcList.slice(0,3)]
  54. }
  55. },
  56. }
  57. </script>
  58. <style>
  59. .box{
  60. width: 300px;
  61. }
  62. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/76783
推荐阅读
相关标签