<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="js/vue.js"></script>
</head>
<body>
<div id="example">
<p v-change>{{msg}}</p>
</div>
<script type="text/javascript">
//创建自定义的指令
//钩子函数 hook function 到了规定阶段自动执行
Vue.directive('change',{
//bind就是钩子函数,会在指令被调用时,自动触发
bind:function(el,binding){
console.log(arguments);
console.log("in bind...");
el.style.background="red";
}
});
new Vue({
el:'#example',
data:{
msg:'VueJS is Awesome'
}
});
</script>
</body>
</html>
自定义指令
最新推荐文章于 2025-01-07 20:20:20 发布