完成这样的一个功能:
在列表随机的位置添加数字,每次添加的数字增加1;也可以单击按钮,随机移除列表中的数字
样例图:
已给出的代码如下:
<!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>
<script src="../js/vue.js"></script>
<style>
/* 数字圆圈部分样式 */
.list-item {
display: inline-block;
margin-right: 10px;
background-color: red;
border-radius: 50%;
width: 25px;
height: 25px;
text-align: center;
line-height: 25px;
color: #fff;
}
</style>
</head>
<body>
<div id="app">
<button @click='addNum'>随机插入一个数字</button>
<button @click="removeNum">随机移除一个数字</button>
</div>
<script>
var vm = new Vue({
el: "#app",
data: {
items: [1, 2, 3, 4],
nextNum: 5,
removedNum: []
}
})
</script>
</body>
</html>