Vue.directive('name_of_the_directive', {
bind(e1, binding, vnode) {
}
})
<html>
<head>
<title>Vue.js Custom Directive</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "directive">
<div v-changestyle>Vue.js Custom Directive Example</div>
</div>
<script type = "text/javascript">
Vue.directive("changestyle",{
bind(e1,binding, vnode) {
console.log(e1);
e1.style.color = "red";
e1.style.fontSize = "20px";
}
});
var vm = new Vue({
el: '#directive',
data: {
},
methods : {
},
});
</script>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#directive',
data: {
},
methods : {
},
})
html, body {
margin: 5px;
padding: 0;
}
Vue.directive("changestyle",{
bind(e1,binding, vnode) {
console.log(e1);
e1.style.color = "red";
e1.style.fontSize = "20px";
}
});
<div v-changestyle>Vue.js Custom Directive Example</div>
v-changestyle = "{color:'the_color_name'}".
<html>
<head>
<title>Vue.js Custom Directive</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "directive">
<div v-changestyle = "{color:'green'}">Passing value to custom directive example</div>
</div>
<script type = "text/javascript">
Vue.directive("changestyle",{
bind(e1,binding, vnode) {
console.log(e1);
console.log(binding.value.color);
console.log(vnode);
e1.style.color=binding.value.color;
e1.style.fontSize = "20px";
}
});
</script>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#directive',
data: {
},
methods : {
},
})
<div v-changestyle = "{color:'green'}">Passing value to custom directive example</div>
Vue.directive("changestyle",{
bind(e1,binding, vnode) {
console.log(e1);
console.log(binding.value.color);
console.log(vnode);
e1.style.color=binding.value.color;
e1.style.fontSize = "20px";
}
});
<html>
<head>
<title>Vue.js Custom Directive</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "directive">
<input v-model = "name" placeholder = "Enter Your Name" /><br/>
<span style = "font-size:20px;"><b>Letter count is : {{name | countletters}}</b></span>
</div>
</script>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#directive',
data: {
name : ""
},
filters : {
countletters : function(value) {
return value.length;
}
}
})
filters : {
countletters : function(value) {
return value.length;
}
}
<span style = "font-size:20px;"><b>Letter count is : {{name | countletters}}</b></span>