成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

Vue實(shí)現(xiàn)簡單圖片切換效果

瀏覽:4日期:2022-09-28 16:34:27

本文實(shí)例為大家分享了Vue實(shí)現(xiàn)簡單圖片切換的具體代碼,供大家參考,具體內(nèi)容如下

Vue實(shí)現(xiàn)簡單圖片切換效果

代碼:

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script> <title>圖片切換</title> <style type='text/css'>*{ padding: 0; margin: 0;}#app{ position: absolute; width: 100px; height: 100px; top: 100px; left: 400px;} #left{ position: relative; top:-240px; left: -45px; font-size: 50px; } #right{ position: relative; top: -300px; left: 595px; font-size: 50px; } a{ color: black; text-decoration: none; } </style></head><body> <div id='app'><!-- 要輪詢的圖片 --> <img :src='http://www.piao2010.com/bcjs/imgArr[index]'/> <!-- 左箭頭 --> <a href='javascript:void(0)' @click='prev' v-show='index!=0'>《</a> <!-- 右箭頭 --> <a href='javascript:void(0)' @click='next' v-show='index<imgArr.length-1'>》</a> </div> <script>var app = new Vue({ el: '#app', data: {imgArr:[ 'img/1.jpg', 'img/2.jpg', 'img/3.jpg', 'img/4.jpg', 'img/5.jpg',],index: 0, }, methods: {prev: function(){ this.index--;},next: function(){ this.index++;}, }}) </script></body></html>

總結(jié):

列表數(shù)據(jù)使用數(shù)組保存; v-bind指令可以設(shè)置元素屬性,如srcv-showv-if都可以切換元素的顯示狀態(tài),但頻繁切換推薦使用v-show

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Vue
相關(guān)文章: