当前位置:   article > 正文

html通过数据改变,图片跟着改变

html通过数据改变,图片跟着改变

改变前 

 改变后

通过数据来控制样式展示 

  1. <template>
  2. <div>
  3. 通过num控制图标是否更改{{num}}
  4. <div class="box">
  5. <!-- 如果num大于1则是另一种,样式,如果小时1,则是另一种样式 -->
  6. <div class="item" :class="num > 1 ? 'noClick' :''" v-for="(item,index) in menuData" :key="index">
  7. <div class="img" :class="item.icon"></div>
  8. <div class="content">{{item.name}}</div>
  9. <div class="arrow"><img src="../assets/evaluateOthers/role-arrow.png" alt=""></div>
  10. </div>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. data () {
  17. return {
  18. num: 10,
  19. menuData: [
  20. {
  21. name: '学不会1',
  22. icon: 'other'
  23. },
  24. {
  25. name: '学不会2',
  26. icon: 'my'
  27. },
  28. {
  29. name: '学不会3',
  30. icon: 'people'
  31. },
  32. {
  33. name: '学不会4',
  34. icon: 'shaicha'
  35. }
  36. ]
  37. }
  38. }
  39. }
  40. </script>
  41. <style lang="less" scoped>
  42. .box {
  43. padding: 20px;
  44. }
  45. .item {
  46. background: #ffffff;
  47. box-shadow: 0px 1px 5px 1px rgba(0, 0, 0, 0.11);
  48. border-radius: 4px;
  49. width: 100%;
  50. margin-bottom: 16px;
  51. padding: 18px 17px 18px 20px;
  52. box-sizing: border-box;
  53. display: flex;
  54. align-items: center;
  55. position: relative;
  56. }
  57. .img {
  58. width: 44px;
  59. height: 44px;
  60. margin-right: 17px;
  61. &.other {
  62. background: url('../assets/evaluateOthers/other-icon.png') no-repeat center;
  63. background-size: 44px;
  64. }
  65. &.my {
  66. background: url('../assets/evaluateOthers/my-icon.png') no-repeat center;
  67. background-size: 44px;
  68. }
  69. &.people {
  70. background: url('../assets/evaluateOthers/people-icon.png') no-repeat center;
  71. background-size: 44px;
  72. }
  73. &.shaicha {
  74. background: url('../assets/evaluateOthers/shaicha.png') no-repeat center;
  75. background-size: 44px;
  76. }
  77. }
  78. // 符合条件后带的样式
  79. .noClick {
  80. .img {
  81. &.other {
  82. background: url('../assets/evaluateOthers/no-other-icon.png') no-repeat
  83. center;
  84. background-size: 44px;
  85. }
  86. &.my {
  87. background: url('../assets/evaluateOthers/wartfor.png') no-repeat center;
  88. background-size: 44px;
  89. }
  90. &.people {
  91. background: url('../assets/evaluateOthers/people-icon.png') no-repeat
  92. center;
  93. background-size: 44px;
  94. }
  95. &.shaicha {
  96. background: url('../assets/evaluateOthers/shaicha.png') no-repeat center;
  97. background-size: 44px;
  98. }
  99. }
  100. }
  101. .arrow {
  102. position: absolute;
  103. right: 14px;
  104. top: 50%;
  105. transform: translate(0, -50%);
  106. }
  107. </style>

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

闽ICP备14008679号