Browse Source

lesson 3: contain the classical event handling within the app.

Frederic G. MARAND 7 years ago
parent
commit
e63de9023c
1 changed files with 9 additions and 6 deletions
  1. 9 6
      lesson3/3.js

+ 9 - 6
lesson3/3.js

@@ -3,13 +3,16 @@ const app = new Vue({
   el: '#root',
   data: {
     names: ['Joe', 'Mary', 'Jane', 'Jack'],
+  },
+
+  mounted() {
+    document.querySelector('#button').addEventListener('click', () => {
+      "use strict";
+      const name = document.querySelector('#input');
+      app.names.push(name.value);
+      name.value = '';
+    });
   }
 });
 
 
-document.querySelector('#button').addEventListener('click', () => {
-  "use strict";
-  const name = document.querySelector('#input');
-  app.names.push(name.value);
-  name.value = '';
-});