本小节学会使用v-show
和@click
、v-bind
,v-bind
可以简写为:
html
<!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>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<body>
<div id="app">
<button v-show="index>0" @click="index--">上一页</button>
<div>
<img :src="list[index]">
</div>
<button v-show="index < list.length-1" @click="index++">下一页</button>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
index: 0,
list: [
'./imgs/001.png',
'./imgs/002.png',
'./imgs/003.png',
'./imgs/004.png'
]
}
})
</script>
</body>
</html>