Просмотр исходного кода

lesson 13: communicate via a top-level object between any components.

Frederic G. MARAND 7 лет назад
Родитель
Сommit
cc02a4b4f9
4 измененных файлов с 127 добавлено и 7 удалено
  1. 50 7
      .idea/workspace.xml
  2. 31 0
      lesson13/code.js
  3. 27 0
      lesson13/index.html
  4. 19 0
      lesson13/styles.css

+ 50 - 7
.idea/workspace.xml

@@ -2,9 +2,9 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="0f813586-48e2-4acf-8923-221617ab434f" name="Default" comment="">
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lesson12/code.js" />
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lesson12/index.html" />
-      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lesson12/styles.css" />
+      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lesson13/code.js" />
+      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lesson13/index.html" />
+      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lesson13/styles.css" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
     </list>
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -16,7 +16,28 @@
   </component>
   <component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
   <component name="FileEditorManager">
-    <leaf />
+    <leaf>
+      <file leaf-file-name="index.html" pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/lesson13/index.html">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="225">
+              <caret line="14" column="32" lean-forward="false" selection-start-line="14" selection-start-column="32" selection-end-line="14" selection-end-column="32" />
+              <folding />
+            </state>
+          </provider>
+        </entry>
+      </file>
+      <file leaf-file-name="code.js" pinned="false" current-in-tab="true">
+        <entry file="file://$PROJECT_DIR$/lesson13/code.js">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="465">
+              <caret line="31" column="0" lean-forward="true" selection-start-line="31" selection-start-column="0" selection-end-line="31" selection-end-column="0" />
+              <folding />
+            </state>
+          </provider>
+        </entry>
+      </file>
+    </leaf>
   </component>
   <component name="FindInProjectRecents">
     <findStrings>
@@ -67,6 +88,8 @@
         <option value="$PROJECT_DIR$/lesson11/code.js" />
         <option value="$PROJECT_DIR$/lesson12/index.html" />
         <option value="$PROJECT_DIR$/lesson12/code.js" />
+        <option value="$PROJECT_DIR$/lesson13/index.html" />
+        <option value="$PROJECT_DIR$/lesson13/code.js" />
       </list>
     </option>
   </component>
@@ -123,7 +146,7 @@
               <option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
             </PATH_ELEMENT>
             <PATH_ELEMENT>
-              <option name="myItemId" value="lesson12" />
+              <option name="myItemId" value="lesson13" />
               <option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
             </PATH_ELEMENT>
           </PATH>
@@ -267,6 +290,9 @@
   <component name="ShelveChangesManager" show_recycled="false">
     <option name="remove_strategy" value="false" />
   </component>
+  <component name="StructureViewFactory">
+    <option name="ACTIVE_ACTIONS" value=",HIDE_INHERITED_FROM_OBJECT" />
+  </component>
   <component name="TaskManager">
     <task active="true" id="Default" summary="Default task">
       <changelist id="0f813586-48e2-4acf-8923-221617ab434f" name="Default" comment="" />
@@ -279,12 +305,13 @@
     <servers />
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="11225000" />
+    <option name="totallyTimeSpent" value="12264000" />
   </component>
   <component name="ToolWindowManager">
     <frame x="0" y="23" width="1440" height="877" extended-state="6" />
+    <editor active="true" />
     <layout>
-      <window_info id="Project" active="true" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2532189" sideWeight="0.5" order="5" side_tool="false" content_ui="combo" />
+      <window_info id="Project" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2532189" sideWeight="0.5" order="5" side_tool="false" content_ui="combo" />
       <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
       <window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
       <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
@@ -692,5 +719,21 @@
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/lesson13/index.html">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="225">
+          <caret line="14" column="32" lean-forward="false" selection-start-line="14" selection-start-column="32" selection-end-line="14" selection-end-column="32" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/lesson13/code.js">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="465">
+          <caret line="31" column="0" lean-forward="true" selection-start-line="31" selection-start-column="0" selection-end-line="31" selection-end-column="0" />
+          <folding />
+        </state>
+      </provider>
+    </entry>
   </component>
 </project>

+ 31 - 0
lesson13/code.js

@@ -0,0 +1,31 @@
+window.Event = new Vue();
+
+Vue.component('coupon', {
+  methods: {
+    onCouponApplied() {
+      Event.$emit('applied');
+    }
+  },
+
+  template: `
+<input placeholder="Enter your coupon code" @blur="onCouponApplied" />  
+`,
+
+});
+
+const app = new Vue({
+  el: '#root',
+  data: {
+    couponApplied: false,
+  },
+
+  created() {
+    Event.$on('applied', this.onCouponApplied);
+  },
+
+  methods: {
+    onCouponApplied() {
+      this.couponApplied = true;
+    }
+  }
+});

+ 27 - 0
lesson13/index.html

@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.2.3/css/bulma.css" />
+    <link rel="stylesheet" href="../styles.css" />
+    <link rel="stylesheet" href="styles.css" />
+  </head>
+  <body>
+    <nav>
+      <h1><span class="index">12</span>Component communication 1: custom events</h1>
+      <ul>
+        <li><a href="../lesson12">Prev</a></li>
+        <li><a href="../lesson14">Next</a></li>
+      </ul>
+    </nav>
+
+    <div id="root" class="container">
+      <coupon @applied="onCouponApplied"></coupon>
+      <h1 v-if="couponApplied">You used a coupon!</h1>
+    </div>
+
+    <script src="../lib/vue-2.1.3.js"></script>
+    <script src="code.js"></script>
+  </body>
+</html>

+ 19 - 0
lesson13/styles.css

@@ -0,0 +1,19 @@
+body {
+  padding-top: 40px;
+}
+
+nav li {
+  display: inline;
+}
+
+nav h1 span {
+  margin-right: 0.3em;
+}
+
+button {
+  display: block;
+}
+
+[v-cloak] {
+  display: none;
+}