当前位置:网站首页>77 global customization instruction
77 global customization instruction
2022-07-20 08:42:00 【longfei815】
77- Global custom instructions - adopt Vue.directive Set up .
The code is as follows :
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>77- Global custom instructions </title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
p{
width: 100px;
height: 100px;
background-color: #fcf;
}
</style>
</head>
<body>
<div id='app'>
<button @click="isShow=!isShow"> Button </button>
<p v-myshow="isShow"></p>
</div>
<script>
Vue.directive("myshow", { // directive It means instruction .
bind(el, binding) {
// When to execute the code here ?
// stay v-myshow Instruction bound to p On the label , Execute the code here , Only execute 1 Time . The page is bound as soon as it is refreshed
// el It's this bound element
// binding It is an object of some information bound this time
// binding.value Useful , Get isShow Value
// demand : As soon as the page is refreshed , Let the box according to isShow Value , To show or hide
console.log("bind", el, binding);
// el.style.display = isShow Value ? "block" : "none"
el.style.display = binding.value ? "block" : "none"
},
update(el, binding) {
// When to execute the code here ?
// When the child node of the bound label changes , Execute the code here
// v-myshow yes p Child nodes of , therefore , as long as v-myshow The value of has changed , Will execute the code here
// After clicking , According to again isShow Show or hide the value of
el.style.display = binding.value ? "block" : "none"
}
})
new Vue({
el:'#app',
data:{
isShow:false
}
})
</script>
</body>
</html>
边栏推荐
- 【学习笔记】Unreal(虚幻)4引擎入门(三)
- C language structure knowledge sharing
- Character functions and string functions
- scroll案例:带有动画的返回顶部
- Chapter 62: blue screen crash when running vs program on win10
- 10. Calculation attribute - calculated
- Greedy - deletion
- JS如何判断当前日期是否在某个范围内
- 习题集
- Learning diary 3- input and output of data
猜你喜欢
冒泡排序思想及实现
Recursive backtracking - maze walking
C language custom types: structure, enumeration, union
Process to thread and incoming thread communication
更易上手的C语言入门级芝士 (1) 数据类型、变量和常量、字符串+转义字符+注释(超详细)
Using C to realize three versions of address book
Greedy - deletion
Easier to use C language entry-level cheese (3) common keywords +define+ pointer + structure (super detailed)
[learning notes] operation summary of "STL speech contest process management system"
7.Object. Defineproperty and data broker (data hijacking)
随机推荐
Easier to use C language entry-level cheese (1) data types, variables and constants, strings + escape characters + comments (super detailed)
59-[重点]Object.defineProperty的get方法
What if the game needs to be reinstalled after the steam folder is moved
4. MVC model and MVVM model
60-[重点]Object.defineProperty的set方法
Standard IO and file IO
【学习笔记】“STL演讲比赛流程管理系统”作业总结
页面搜索高亮功能,页面自动匹配关键字滚动到屏幕正中间,并高亮显示。
C语言 --- 商品信息管理系统
66-[重点]v-for指令的key属性
学习日记1
简单的本地图片服务器的搭建
59-[key]object Get method of defineproperty
原生JS完美实现深拷贝
三子棋(N子棋)C语言编程实现,超详细讲解
七牛云:上传图片+删除图片
Easily master | struct structure | knowledge points
c语言自定义类型:结构体、枚举、联合
数组合并方法:concat( )
学习日记5-C语言函数的应用