使用到了vue简单指令v-bind
html代码:
<!-- v-bind动态设置标签属性 -->
<div id="app1">
<button v-show="index > 0" @click="index--">上一页</button>
<!-- <img v-bind:src="imgUrl" v-bind:title="msg" alt="" style="width: 100px;height: 100px;"> -->
<!-- 简写: -->
<img :src="list[index]" :title="msg" alt="" style="width: 100px;height: 100px;">
<button v-show="index < list.length - 1" @click="index++">下一页</button>
</div>
js代码:
<script src="./vue.js"></script>
<script>
const app1 = new Vue({
el: '#app1',
data: {
index: 0,
list: [
'./img/10-01.png',
'./img/10-02.png',
'./img/11-00.gif',
'./img/11-01.gif',
'./img/11-03.gif',
'./img/11-04.png',
'./img/11-05.png'
],
msg: '懒洋洋'
}
})
效果图:
总结:
通过v-bind改变图片路径
通过index判断是否隐藏按钮