【发布时间】:2018-09-04 16:20:25
【问题描述】:
我想在单击缩略图时显示带有图片的文本,并且我编写了一个方法来执行此类操作,但我不知道为什么我的文本无法出现在我的网站上。 因为我在我的 JS 中创建了一个方法来显示缩略图下的文本,我在我的 JS 模板部分调用了这个函数。 你能帮帮我吗?
Vue.component('carousel', {
template: `
<div class="card-carousel" >
<div class="thumbnails">
<div
v-for="(image, index) in images"
:key="image.id"
:class="['thumbnail-image', (activeImage == index) ? 'active' : '']"
@click="activateImage(index)" @click="activateText(index)">
<img :src="image.thumb">
</div>
</div>
<div class="containe-carousel">
<div class="photoshop-screenshot">
<img :src="currentImage" alt="">
</div>
<div class="card-img">
<img :src="currentImage2" alt="">
</div>
</div>
</div>
`,
computed: {
currentImage() {
return this.images[this.activeImage].big;
},
currentImage2() {
return this.images[this.activeImage].big2;
},
currentText (){
return this.texts[this.activeText].text;
}
},
data() {
return {
activeImage: 0,
activeText :0,
}
},
methods: {
activateImage(imageIndex) {
this.activeImage = imageIndex;
},
activeText (imageIndex){
this.activeText = imageIndex;
}
},
props: ['images', 'texts']
})
<script>
var app = new Vue({
el: '#app',
data() {
return {
images: [
{
id: '1',
big: '/images/keyboard1/photoshop-profile.PNG',
big2: '/images/keyboard1/photoshop-screenshot.png',
text : 'photo 1',
thumb: '/images/keyboard1/photoshop-logo.jpg'
},
{
id: '2',
big: '/images/keyboard2/autocad-profile.png',
big2: '/images/keyboard2/autocad-screenshot.png',
text : 'photo 2',
thumb: '/images/keyboard2/autocad-logo.png'
},
{
id: '3',
big: '/images/keyboard3/counterstrike-profile.png',
big2: '/images/keyboard3/counterstrike-screenshot.jpg',
thumb: '/images/keyboard3/counterstrike-logo.png'
},
{
id: '4',
big: '/images/keyboard4/leagueoflegends-profile.png',
big2: '/images/keyboard4/leagueoflegends-screenshot.png',
thumb: '/images/keyboard4/leagueoflegends-logo.jpg'
}
]
}
}
});
</script>
CSS:
.section{
background-color: black;
}
.card-carousel {
user-select: none;
position: relative;
}
.thumbnails {
display: flex;
justify-content: space-evenly;
flex-direction: row;
}
.thumbnail-image {
display: fixed;
align-items: center;
cursor: pointer;
padding: 2px;
}
.thumbnail-image > img {
width: 100%;
height: auto;
transition: all 250ms;
filter: grayscale(100%);
}
.thumbnail-image:selected> img {
box-shadow: 2px 2px 6px 1px rgba(0,0,0, 0.5);
visibility: hidden;
filter: none;
}
.card-img {
position: relative;
}
.card-img > img {
margin: 0 auto;
padding-top: 7%;
z-index: 2;
}
.photoshop-screenshot {
position:absolute;
z-index: 1;
width: 70%;
right:-80px;
bottom:-130px;
}
【问题讨论】:
标签: javascript html css vue.js vuejs2