<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script type="text/javascript" src='vue.min.js'></script> <title></title> <style type="text/css"> body{background: #ccc;} </style> </head> <body> <input type="button" name="" id="" value="changed" @click="fn"/> <img v-bind:src="url" /> ,<script type="text/javascript"> new Vue( { el:'body', data:{ url:'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white_fe6da1ec.png' }, methods:{ 'fn':function() { this.url = 'https://p.ssl.qhmsg.com/d/inn/6ea3b7d2/pc/p_weishi.png' } } } ); </script> </body> </html>解释:
如果是使用v-bind:src=“url"vue的方法,就可以不加模板{{}}
使用原生的方法src=”"就要加模板{{}}.
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script type="text/javascript" src='vue.min.js'></script> <title></title> <style type="text/css"> body{background: #ccc;} </style> </head> <body> <input type="button" name="" id="" value="changed" @click="fn"/> <img v-bind:src="url" /> ,<script type="text/javascript"> new Vue( { el:'body', data:{ num:0, url:'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white_fe6da1ec.png' }, methods:{ fn:function() { this.num++; this.num%2==1? this.url = 'https://p.ssl.qhmsg.com/d/inn/6ea3b7d2/pc/p_weishi.png':this.url='https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white_fe6da1ec.png'; } } } ); </script> </body> </html>解释:
第一步:默认是百度,
第二步:点击就num=1,然后满足条件是360
第三步;再点击是num=2,就变会百度了…
效果: