2 changed files with 50 additions and 24 deletions
@ -0,0 +1,44 @@ |
|||||
|
<template> |
||||
|
<div> |
||||
|
<button v-on:click="index -= 1"><</button> |
||||
|
<button v-on:click="index += 1">></button> |
||||
|
<div> |
||||
|
{{ images[index].src }}<br> |
||||
|
{{ images[index].title }} |
||||
|
</div> |
||||
|
<button v-on:click="index = i" v-for="(img, i) in images" :key="i" :title="img.title" v-bind:class="{active: i == index}"></button> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
export default { |
||||
|
props: { |
||||
|
images: {default: () => [{src: "", title: ""}]} |
||||
|
}, |
||||
|
data: function() { |
||||
|
return { |
||||
|
index: 0 |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
|
||||
|
}, |
||||
|
watch: { |
||||
|
index: function(value) { |
||||
|
let total = this.images.length - 1; |
||||
|
if (value < 0) { |
||||
|
this.index = total; |
||||
|
} |
||||
|
else if (value > total) { |
||||
|
this.index = 0; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<style> |
||||
|
.active { |
||||
|
background-color: green; |
||||
|
} |
||||
|
</style> |
Loading…
Reference in new issue