<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
* {
margin: 0;
padding: 0;
}
#app {
width: 1000px;
height: 200px;
overflow: hidden;
}
li {
width: 200px;
height: 200px;
border: 1px solid red;
box-sizing: border-box;
float: left;
}
.select {
background: pink;
}
li {
list-style: none;
}
</style>
<body>
<!-- style=" margin-left: 500px;" -->
<ul id="app">
<li v-for="(item,index) in list" @mouseover="move(index)" @mouseout="out()" @click="handleClick(index)"
:class="flag>=index?'select':''">
<p>key:{{index}}</p>
<p>flag:{{flag}}</p>
<p>cur:{{cur}}</p>
<p>{{flag>=index}}</p>
</li>
</ul>
</body>
</html>
<script>
var app = new Vue({
el: '#app',
data: {
flag: -1,
cur: -1,
list: [{
number: 0
}, {
number: 1
}, {
number: 2
}, {
number: 3
}, {
number: 4
}]
},
methods: {
handleClick(i) {
this.cur = i
},
move(i) {
console.log(i)
this.flag = i
},
out() {
this.flag = -1
if (this.cur == -1) {
console.log("用户没有点击")
} else {
this.flag = this.cur
}
// if (this.cur !== -1) {
// this.flag = this.cur
// } else {
// this.flag = -1
// }
}
},
})
</script>
超简洁原生js结合Vue的星星评分源码
最新推荐文章于 2024-11-13 11:52:56 发布