vue.js 自定义指令directives,Vue.directive使用

92 篇文章 0 订阅
15 篇文章 0 订阅

vue.js 自定义指令directives,Vue.directive使用

 

================================

©Copyright 蕃薯耀 2018年12月06日

http://fanshuyao.iteye.com/

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>vue.js 自定义指令directives</title>
<style type="text/css">
[v-cloak]{
	display: none;
}
</style>
</head>
<body>
	
	<div id="vueDiv">
		
		<div style="margin-top: 30px;">
			<div v-upper-text="text"></div>
		</div>
		
	</div>
	
	<div id="innerVueDiv">
		
		<div style="margin-top: 30px;">
			<div v-lower-text="innerText"></div>
		</div>
		
	</div>

<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript">
//自定义全局指令
//el:指令属性所在的html标签对象
//binding:包含指令相关信息数据的对象
Vue.directive("upper-text", function(el, binding){
	console.log(el);
	console.log(binding);
	el.textContent = binding.value.toUpperCase();
});

var vueObj = new Vue({
	el : "#vueDiv",
	data : {
		text : "Never Give Up!",
	}
});

var innerVueObj = new Vue({
	el : "#innerVueDiv",
	data : {
		innerText : "Never Give Up!(innerText)",
	},
	directives : {//局部指令,只在当前Vue中才有效
		"lower-text" : function(el, binding){
			el.textContent = binding.value.toLowerCase();
		}
	}
});
</script>
</body>
</html>

 

 

================================

©Copyright 蕃薯耀 2018年12月06日

http://fanshuyao.iteye.com/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值