#vue点击切换图片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>切换图片</title>
<style>
ul li{
float: left;
cursor: pointer;
list-style: none;
padding: 10px;
}
.liBgcolor{
background-color: red;
}
.divBorder{
border: 2px solid pink;
}
.divNone{
display: none;
}
div{
width: 400px;
height: 250px;
}
</style>
</head>
<body>
<div id="app">
<ul>
<li v-for="(item, index) in heroArr" :key="item.id" @click="checkIndex(index)" :class="currentIndex==index ? 'liBgcolor': ''">{{item.name}}</li>
</ul>
<div style="clear: both;" v-for="(item, index) in heroArr" :key="item.id" :class="currentIndex==index ? 'divBorder div' : 'divNone'">
<img :src="item.path" style="width: 400px;">
</div>
</div>
<script src="./vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
currentIndex:0,
heroArr:[
{
id:1,
name: '射手',
path :'./img/OIP-C (1).jpg'
},
{
id:2,
name: '辅助',
path :'./img/OIP-C (3).jpg'
},
{
id:3,
name: '上单',
path :'./img/R-C.jpg'
},
{
id:4,
name: '打野',
path :'./img/OIP-C.jpg'
},
{
id:5,
name: '中单',
path :'./img/OIP-C (2).jpg'
}
]
},
methods: {
checkIndex(index) {
console.log(index);
this.currentIndex = index;
},
},
})
</script>
</body>
</html>