- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>事件的基本处理title>
- <script type="text/javascript" src="../js/vue.js">script>
- head>
- <body>
- <div id="root">
- <h2>欢迎来到{{name}}h2>
-
- <button @click="show($event,66)">请点击我button>
- div>
- <script type="text/javascript">
- const vm = new Vue({
- el: '#root',
- data: {
- name: '空谷有来人',
- },
- methods: {
- show(event, number) {
- console.log(number)
- alert('欢迎你')
- },
- },
- })
- script>
- body>
- html>
- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>事件修饰符title>
- <script type="text/javascript" src="../js/vue.js">script>
- <style>
- * {
- margin-top: 20px;
- }
- .demo1 {
- height: 50px;
- background-color: aquamarine;
- }
- .box1 {
- padding: 5px;
- background-color: aqua;
- }
- .box2 {
- background-color: orange;
- }
- style>
- head>
- <body>
- <div id="root">
- <h2>欢迎来到{{name}}h2>
-
- <a href="https://www.baidu.com" @click.prevent="showinfo">点击我a>
-
- <div class="demo1" @click="showinfo">
-
- <button @click.stop="showinfo">点击我button>
- div>
-
-
- <button @click.once="showinfo">点击我button>
-
-
- <div class="box1" @click.capture="showMsg(1)">
- div1
- <div class="box2" @click="showMsg(2)">div2div>
- div>
-
- <div class="demo1" @click.self="showinfo">
-
- <button @click="showinfo">点击我button>
- div>
- div>
-
- <script type="text/javascript">
- new Vue({
- el: '#root',
- data: {
- name: '空谷有来人',
- },
- methods: {
- showinfo(e) {
- // e.preventDefault()
- // e.stopPropagation()
- // console.log(e.target)
- alert('欢迎')
- },
- showMsg(num) {
- console.log(num)
- },
- },
- })
- script>
- body>
- html>
我是空谷有来人,感谢大家支持!