天天看點

vue.js 屬性(核心)

<!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>           

複制

解釋:

vue.js 屬性(核心)

如果是使用v-bind:src=“url"vue的方法,就可以不加模闆{{}}

使用原生的方法src=”"就要加模闆{{}}.

效果:

vue.js 屬性(核心)
vue.js 屬性(核心)
<!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>           

複制

解釋:

第一步:預設是百度,

vue.js 屬性(核心)

第二步:點選就num=1,然後滿足條件是360

vue.js 屬性(核心)

第三步;再點選是num=2,就變會百度了…

效果:

vue.js 屬性(核心)
vue.js 屬性(核心)