vue2事件处理器的用法
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>实例title>
- <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js">script>
- head>
- <body>
- <div id="app">
- <button v-on:click="counter += 1">增加 1button>
- <p>这个按钮被点击了 {{ counter }} 次。p>
- div>
-
- <script>
- new Vue({
- el: '#app',
- data: {
- counter: 0
- }
- })
- script>
- body>
- html>
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>实例title>
- <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js">script>
- head>
- <body>
- <div id="app">
-
- <button v-on:click="greet">Greetbutton>
- div>
-
- <script>
- var app = new Vue({
- el: '#app',
- data: {
- name: 'Vue.js'
- },
- // 在 `methods` 对象中定义方法
- methods: {
- greet: function (event) {
- // `this` 在方法里指当前 Vue 实例
- alert('Hello ' + this.name + '!')
- // `event` 是原生 DOM 事件
- if (event) {
- alert(event.target.tagName)
- }
- }
- }
- })
- // 也可以用 JavaScript 直接调用方法
- app.greet() // -> 'Hello Vue.js!'
- script>
- body>
- html>
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>实例title>
- <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js">script>
- head>
- <body>
- <div id="app">
- <button v-on:click="say('hi')">Say hibutton>
- <button v-on:click="say('what')">Say whatbutton>
- div>
-
- <script>
- new Vue({
- el: '#app',
- methods: {
- say: function (message) {
- alert(message)
- }
- }
- })
- script>
- body>
- html>
...
...
Do something
觉得有用可以点赞或收藏 !