test.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view>
  3. <ul>
  4. <li v-for="(item,index) in data1">
  5. <span @click.stop="toggle(index)"></span>
  6. <span>{{item.id}}</span>--
  7. <span>{{item.name}}</span>
  8. <div v-show="(cIndex == index) && dialog" class="modalDiaLog">dialog</div>
  9. </li>
  10. </ul>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. dialog: false,
  18. cIndex: -1,
  19. data1: [{
  20. id: 1,
  21. name: "a"
  22. },
  23. {
  24. id: 2,
  25. name: "b"
  26. },
  27. {
  28. id: 3,
  29. name: "c"
  30. },
  31. {
  32. id: 4,
  33. name: "d"
  34. },
  35. ]
  36. }
  37. },
  38. mounted() {
  39. document.addEventListener('click', (e) => {
  40. if (e.target.className != 'modalDiaLog') {
  41. this.dialog = false;
  42. }
  43. })
  44. },
  45. methods: {
  46. toggle(index) {
  47. this.cIndex = index;
  48. this.dialog = !this.dialog;
  49. }
  50. }
  51. }
  52. </script>
  53. <style>
  54. ul,
  55. li {
  56. list-style: none;
  57. }
  58. li {
  59. position: relative;
  60. height: 40px;
  61. line-height: 40px;
  62. border-bottom: 1px solid #000;
  63. }
  64. li span:first-child {
  65. display: inline-block;
  66. width: 10px;
  67. height: 10px;
  68. background-color: #000;
  69. }
  70. li div {
  71. position: absolute;
  72. left: 20px;
  73. top: 0;
  74. z-index: 1000;
  75. width: 100px;
  76. height: 100px;
  77. border: 1px solid red;
  78. background-color: #fff;
  79. }
  80. </style>