<!DOCTYPE html> <html> <head> <title> </title> </head> <body> <div id="app"> <ol> <li v-for="(item,key,index) in obj"><input type="button" :value="key" name="" @click="changeImage"></li> </ol> <div> <img :src="imgSrc"> </div> </div> <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> <script type="text/javascript"></script> <script type="text/javascript"> //在原生js中使用 var obj={ name:‘Source/image/r1.jpg‘, name1:‘Source/image/r2.jpg‘, name2:‘Source/image/r3.jpg‘ }; new Vue({ el: ‘#app‘, data: { obj, imgSrc:‘Source/image/r1.jpg‘ }, methods:{ changeImage:function(event){ this.imgSrc=this.obj[event.target.value]; } } }) </script> </body> </html>
image的src使用相对路径,效果如下图