vue2.0—— Vue.directive
来源:互联网 发布:服务器托管数据安全 编辑:程序博客网 时间:2024/05/29 03:59
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>全局API Vue.directive自定义指令 09</title>
<script src="../assets/js/vue.js"></script>
<link type="text/css" rel="stylesheet" href="../assets/css/index.css" />
</head>
<body>
<h1>全局API 自定义指令</h1>
<hr />
<div id="app">
<div v-wos.color="color" id="aaa">
{{num}}
</div>
<p>
<button @click="jia">+</button>
</p>
</div>
<button onclick="xiezai()">解绑</button>
<script>
function xiezai(){
vm.$destroy();
}
Vue.directive('wos',{ //我是全局API 是自定义指令
bind:function(el,binding,vnode){ //我加上下面的四个都是生命周期 我是指令的生命周期
console.log('1-bind'); //当被绑定
var s = JSON.stringify;
el.innerHTML =
'name' + s(binding.name) + '<br>' +
'value' + s(binding.value) + '<br>' +
'expression' + s(binding.expression) + '<br>'+
'modifiers' + s(binding.modifiers)
el.style = 'color:'+binding.value
},
inserted:function(){//当绑定到节点 已经插入完成了
console.log('2-inserted');
},
update:function(el,binding,vnode){//组件更新
console.log('3-update');
el.style = 'color:green'
},
componentUpdated:function(){//组件更新完成
console.log('4-componentUpdated');
},
unbind:function(){//卸载 解绑
console.log('5-unbind');
}
}
);
//全局API是不在构造器里面 通过构造器的命名 给Vue写一些全局的 全局API建议写在构造器的上面
var vm = new Vue({ //建立一个构造器
el:"#app", //构造器的作用域在哪里
data:{
num:10,
color:'red'
},
methods:{
jia:function(){
this.num++;
}
}
});
</script>
<script src="./webpack.js"></script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>全局API Vue.directive自定义指令 09</title>
<script src="../assets/js/vue.js"></script>
<link type="text/css" rel="stylesheet" href="../assets/css/index.css" />
</head>
<body>
<h1>全局API 自定义指令</h1>
<hr />
<div id="app">
<div v-wos.color="color" id="aaa">
{{num}}
</div>
<p>
<button @click="jia">+</button>
</p>
</div>
<button onclick="xiezai()">解绑</button>
<script>
function xiezai(){
vm.$destroy();
}
Vue.directive('wos',{ //我是全局API 是自定义指令
bind:function(el,binding,vnode){ //我加上下面的四个都是生命周期 我是指令的生命周期
console.log('1-bind'); //当被绑定
var s = JSON.stringify;
el.innerHTML =
'name' + s(binding.name) + '<br>' +
'value' + s(binding.value) + '<br>' +
'expression' + s(binding.expression) + '<br>'+
'modifiers' + s(binding.modifiers)
el.style = 'color:'+binding.value
},
inserted:function(){//当绑定到节点 已经插入完成了
console.log('2-inserted');
},
update:function(el,binding,vnode){//组件更新
console.log('3-update');
el.style = 'color:green'
},
componentUpdated:function(){//组件更新完成
console.log('4-componentUpdated');
},
unbind:function(){//卸载 解绑
console.log('5-unbind');
}
}
);
//全局API是不在构造器里面 通过构造器的命名 给Vue写一些全局的 全局API建议写在构造器的上面
var vm = new Vue({ //建立一个构造器
el:"#app", //构造器的作用域在哪里
data:{
num:10,
color:'red'
},
methods:{
jia:function(){
this.num++;
}
}
});
</script>
<script src="./webpack.js"></script>
</body>
</html>
0 0
- vue2.0—— Vue.directive
- Vue——自定义指令directive
- 【13】vue.js — 自定义指定(directive)
- Vue2 自定义全局指令Vue.directive和指令的生命周期
- vue2.0项目快速搭建工具——vue-cli
- vue学习笔记04——vue2.0的变化
- Vue2.0史上最全入坑教程(上)—— 搭建Vue脚手架(vue-cli)
- Vue2.0学习笔记(上)—— 搭建Vue脚手架(vue-cli)
- Vue2.0 史上最全入坑教程(上)—— 搭建 Vue 脚手架(vue-cli)
- Vue2.0史上最全入坑教程(上)—— 搭建Vue脚手架(vue-cli)
- vue2.0项目笔记系列(1)——搭建Vue脚手架(vue-cli)
- Vue2.0史上最全入坑教程(上)—— 搭建Vue脚手架(vue-cli)
- Vue2.0史上最全入坑教程(上)—— 搭建Vue脚手架(vue-cli)
- Vue2.0的变化(2)———vue2.0动画的变化、vue-2.0路由的变化
- vue2.0路由--vue-router
- vue2.0,vue-router配置
- vue2.0使用vue-router
- Vue2.0配置vue-router
- iOS更改app的icons
- C++类模板分离模式
- reactnative "borderBottom" is not a valid style property.styleError
- Mybatis——Invalid bound statement (not found)-Could not find result map java.lang.Integer
- Qt5.8我目前遇到的一些问题及解决方法
- vue2.0—— Vue.directive
- jquery版本对浏览器的兼容
- 题目1479:移位和旋转
- Glide加载网络图片,服务器内容更新但是Glide缓存无法清理的解决办法
- Linux查看物理CPU个数、核数、逻辑CPU个数
- Android-4大组件
- vue2.0心得感悟
- Xilinx Zynq7000系列学习
- war 包存放位置的配置