前端知识学习07

1.js事件冒泡

  1. e.stopPropagation()
  2. 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会把其包裹的所有组件都缓存起来,主要用于保留组件状态或避免重新渲染。

posted @ 2022-05-19 00:20  侠客小飞  阅读(29)  评论(0编辑  收藏  举报