前端知识学习07
1.js事件冒泡
- e.stopPropagation()
- e.cancelBubble = true
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="s1">s1
<div id="s2">s2</div>
</div>
<script>
s1.addEventListener("click",function(e){
console.log("s1 冒泡事件");
},false);
s2.addEventListener("click",function(e){
// e.stopPropagation()//阻止冒泡
// e.cancelBubble = true //事件捕获
console.log("s2 冒泡事件");
},false);
</script>
</body>
</html>
2.keep-alive
keep-alive会把其包裹的所有组件都缓存起来,主要用于保留组件状态或避免重新渲染。
代码成就万世基积沙镇海
梦想永在凌云意意气风发