Browse Source

lesson 5: binding attributes with v-bind:<attr> or just :<attr>.

Frederic G. MARAND 7 years ago
parent
commit
3ba589a140
3 changed files with 34 additions and 0 deletions
  1. 14 0
      lesson5/code.js
  2. 17 0
      lesson5/index.html
  3. 3 0
      lesson5/styles.css

+ 14 - 0
lesson5/code.js

@@ -0,0 +1,14 @@
+
+const app = new Vue({
+  el: '#root',
+  data: {
+    title: "Now the title is set through JavaScript",
+  },
+
+  methods: {
+    onClick(e) {
+      alert(e.target.textContent);
+    }
+  },
+});
+

+ 17 - 0
lesson5/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+    <link rel="stylesheet" href="styles.css" />
+  </head>
+  <body>
+    <div id="root">
+      <button v-on:click="onClick" v-bind:title="title">Hover over me</button>
+      <button @click="onClick" :title="title">Over me too</button>
+    </div>
+
+    <script src="../lib/vue-2.1.3.js"></script>
+    <script src="code.js"></script>
+  </body>
+</html>

+ 3 - 0
lesson5/styles.css

@@ -0,0 +1,3 @@
+[v-cloak] {
+  display: none;
+}