Browse Source

kolotoč jako komponenta

master
Jméno Příjmení 4 years ago
parent
commit
68a6b870fc
  1. 44
      bak/src/components/Kolotoc.vue
  2. 30
      src/App.vue

44
bak/src/components/Kolotoc.vue

@ -0,0 +1,44 @@
<template>
<div>
<button v-on:click="index -= 1">&lt;</button>
<button v-on:click="index += 1">&gt;</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>

30
src/App.vue

@ -1,25 +1,20 @@
<template>
<div id="app">
<h1>Kolotoč</h1>
<div>
<button v-on:click="index -= 1">&lt;</button>
<button v-on:click="index += 1">&gt;</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>
<Kolotoc :images="images" />
</div>
</template>
<script>
import Kolotoc from './components/Kolotoc';
export default {
name: 'App',
components: {
Kolotoc
},
data: function() {
return {
index: 0,
images: [
{
src: "/img/image_01.jpg",
@ -35,23 +30,10 @@ export default {
}
],
}
},
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…
Cancel
Save