SoFunction
Updated on 2025-04-05

The usage of the event modifier.self based on (detailed explanation)

.self can be understood as skipping bubble events and capturing events, and only events that act directly on this element can be executed.

The code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>self</title>
 <script src=""></script>
 <!--'''''''''''''''''''Please introduce it yourself-->
</head>
<style type="text/css">
 * {
  margin: 0 auto;
  text-align:center;
  line-height: 40px;
 }
 div {
  width: 100px;
 }
 #obj1 {
  background: deeppink;
 }
 #obj2 {
  background: pink;
 }
 #obj3 {
  background: hotpink;
 }
 #obj4 {
   background: #ff4225;
  }
</style>
<script src=""></script>
</head>
<body>
<!--Clickobj4It will be displayed separately when: obj4、 obj3、 obj1;
.selfIt will monitor whether the event is directly affectedobj2superior,If not,Then bubbling and skipping the element,-->
<div >
 <div  v-on:click="doc">
  obj1
  <div  v-on:="doc">
   obj2
   <!--只有Clickobj2才可以出发其Click事件。-->
   <div  v-on:click="doc">
    obj3
    <div  v-on:click="doc">
     obj4
    </div>
   </div>
  </div>
 </div>
</div>
<script type="text/javascript">
 var content = new Vue({
  el: "#content",
  data: {
   id: ''
  },
  methods: {
   doc: function () {
    = ;
    alert()
   }
  }
 })
</script>
</body>
</html>

The above article is based on the usage of self (detailed explanation) based on the event modifier in China. I hope it can give you a reference and I hope you can support me more.