| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <template>
- <div class="hello">
- <div class="image-switcher">
- <img :src="images[currentImageIndex]" alt="Switchable image" />
- <div class="controls">
- <button @click="switchImage">切换图片</button>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: 'ImageChange',
- data() {
- return {
- images: [require('@/assets/1.jpg'), require('@/assets/2.png')],
- currentImageIndex: 0,
- };
- },
- methods: {
- switchImage() {
- this.currentImageIndex = (this.currentImageIndex + 1) % this.images.length;
- },
- },
- };
- </script>
- <style scoped>
- .image-switcher {
- margin: 20px 0;
- text-align: center;
- }
- .image-switcher img {
- width: 300px;
- max-width: 100%;
- height: 300px;
- margin-bottom: 10px;
- }
- .controls button {
- padding: 8px 16px;
- color: white;
- cursor: pointer;
- background-color: #42b983;
- border: none;
- border-radius: 4px;
- }
- .controls button:hover {
- background-color: #3aa876;
- }
- </style>
|