angular.module( 'myapp' ,[])
.directive (myDirective,function (){
return{
template : '',
restrict: '',
replace: '',
........
}
})
Vue.directive('my-directive', {
bind: function(){
//做绑定的准备工作
//比如添加事件监听器,或是其他只需要执行一次的复杂操作
},
inserted: function(){
//...
},
update: function(){
//根据获得的新值执行对应的更新
//对于初始值也会调用一次
},
componentUpdated: function(){
//...
},
unbind: function(){
//做清理操作
//比如移除bind时绑定的事件监听器
}
})
<div v-my-directive = 'someValue'></div>
Vue.directive( 'my-directive',function (value) {
// 这个函数作用 update()
})
//注册一个全局自定义指令v-focus
// 当绑定元素插入到DOM中
// 聚焦元素
<div id="app">
<input v-focus>
/div>
Vue.directive('focus', {
inserted: function (el) {
el.focus() }
});
var app = new Vue({
el: '#app'
});
<div id="example" v-demo-directive:red="message"></div>
<script>
Vue.directive('demoDirective', {
bind: function(el, binding, vnode){
el.style.color = '#fff'
el.style.backgroundColor = binding.arg
el.innerHTML =
'指令名 name:' + binding.name + '<br>' +
'指令绑定值 value:' + binding.value + '<br>' +
'指令绑定表达式expression:' + binding.expression + '<br>' +
'传入指令的参数argument - ' + binding.arg + '<br>'
},
});
var demo = new Vue({
el: '#example',
data: {
message: 'hello!'
}
})
</script>
<div id="app" v-demo-directive="{ color: 'white', text: 'hello!' }"></div>
Vue.directive('demoDirective', function(el, binding, vnode){
console.log(binding.value.color);
console.log(binding.value.text);
});
var demo = new Vue({
el: '#app'
})
div id="isExample" v-myEx.literal = 'foo bar baz'></div>
Vue.directive('myEx',function(el, binding, vnode){
console.log(binding.value.literal)
})
var hah = new Vue({
el: '#isExample'
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有