- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > JavaScript >
- Vue.js實(shí)現圖片切換功能
本文實(shí)例為大家分享了Vue.js實(shí)現圖片切換功能的具體代碼,供大家參考,具體內容如下
實(shí)現功能如下
文件目錄如下,要實(shí)現本功能只需要修改圖片的存儲位置即可
代碼如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="js/vue.js" type="text/javascript" charset="utf-8"></script> </head> <style type="text/css"> div { margin: 0 auto; width:200px; height: 300px; border: 1px solid aqua; } img { margin: 0 auto; width: 200px; height: 250px; border: 1px solid aqua; } </style> <body> <div id="app"> <img :src="imgSrc[index]" > <button type="button" @click="prephoto()">上一張</button> <button type="button" @click="nextphoto()">下一張</button> </div> <script type="text/javascript"> var app = new Vue({ el:"#app", data:{ imgSrc:["./img/1.jpg","./img/2.jpg"], index:1 }, methods:{ prephoto:function(){ this.index--; if(this.index===-1) { this.index=this.imgSrc.length-1; } console.log(this.index) }, nextphoto:function(){ this.index++; if(this.index===this.imgSrc.length){ this.index=0; } console.log(this.index) } } }) </script> </body> </html>
適合初學(xué)者。
以上就是本文的全部?jì)热?,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站