Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.58 KB | None | 0 0
  1. # Welcome to Vue.js
  2.  
  3. Vue.js is a reactive javascript framework that competes with the likes of;
  4.  
  5. * Angular
  6. * React
  7. * Riot
  8. * Ember
  9. * Polymer
  10.  
  11. It does all that fancy binding, isolates scope sensibly and has a relatively shallow learning curve compared to the likes of Angular or Polymer.
  12.  
  13. # Step 1
  14. Basic data binding
  15.  
  16. Standard binding with {{ varName }} as long as that chunk of html is being controlled by Vue.
  17.  
  18. !! Show basic vue instance setup !!
  19.  
  20. !! Explain laravel blade @{{ prefix !!
  21.  
  22. # Step 2
  23. Binding is 2-way (by default, if you want)
  24.  
  25. !! Show v-model on input !!
  26.  
  27. # Step 3
  28. Rendering a list with v-for
  29.  
  30. !! Show how the data field works, show alternate funciton return method so data doesn't end up reused when not expected !!
  31.  
  32. # Step 4
  33. Uppercase filter
  34.  
  35. !! Show filter and pipe !!
  36.  
  37. # Step 5
  38. Lowercase filter
  39.  
  40. !! Show filter and pipe !!
  41.  
  42. # Step 6
  43. ucfirst functionality (on entire string, not per-word)
  44.  
  45. # Step 7
  46. json filter for displaying data
  47.  
  48. !! Explain how it's useful for debugging !!
  49.  
  50. # Step 8
  51. Filters can have arguments, this one modifies the indentation of each level of the json.
  52.  
  53. !! Arguments are space-separated after the filter name !!
  54.  
  55. # Step 9
  56. We've been using v-for but how can we control it? With filters! orderBy
  57.  
  58. !! Show how it's "orderBy 'fieldName' optional order inversion" !!
  59.  
  60. # Step 10
  61. Another filter for v-for called filterBy
  62.  
  63. !! Show how it's filtering on capital C in the field 'name', switch this up as a demo !!
  64.  
  65. # Step 11
  66. Custom components time!
  67. We can create our own tags
  68. `<customtag></customtag>`
  69. Just like in other frameworks.
  70.  
  71. !! Show how we can define the template and then use hook it up to the component !!
  72.  
  73. !! Explain why I added data !!
  74.  
  75. # Step 12
  76. Simplified component definition
  77.  
  78. !! Explain component definition flexiblity.!!
  79.  
  80. !! Copy below in for template tag method !!
  81. ```
  82. <template id="personcomponent">
  83. <div>I'm a Person Component</div>
  84. </template>
  85. ```
  86.  
  87. # Step 13
  88. Now the component is actually doing something.
  89.  
  90. !!Show how it defines "props" and how that gets sucked in.!!
  91.  
  92. !! Show how this could also be v-bind:person !!
  93.  
  94. # Step 14
  95. Computed properties are helpful if you need to transform some data between the model and the view.
  96.  
  97. !! Show the salary computed property function. Show that we're also applying the 'currency' filter so it formats it nicely !! `"£"`
  98.  
  99. !! Maybe demonstrate VUE devtools chrome extension !!
  100.  
  101. # Step 15
  102. v-model binding is dynamic, even for computed properties
  103.  
  104. !! Show how all the data changes, even the root data object !!
  105.  
  106. !! Remark that computed properties are getter-only by default but a set function can be defined to make them two-way (splitting first and last names out of one input field) !!
  107.  
  108. # Step 16
  109. Methods are local to the component they are defined on. This is pretty handy for segregating functionality by components. You define them similarly to computed properties.
  110.  
  111. !! Show remove function, also remark how I had to to track the index (provided by default on v-for as $index) and traverse to the parent and snip the person out of the parent's array using the index !!
  112.  
  113. # Step 17
  114. Let's build an app. And let's do it sensibly. I'm going to use the following to accomplish this;
  115. * Gulp
  116. * Browserify via npm
  117. * Vueify via npm automagically hooks into browserify
  118. * Separate app and component .vue files for sanity
  119.  
  120. This means we'll run a gulp task (default gulp task in this case) whenever we change a .vue file so it is bundled up with all the depenedencies and mashed into /js/demo.js
  121.  
  122. !! Explain the example.io idea and that we'll just be showing example cards with comments and pagination as an end goal !!
  123.  
  124. # Step 18
  125. To set this up we'll add an `<app></app>` tag into our html as well as pull in js/demo.js. In our HTML this is almost all we'll have to do from here on out (almost)!
  126.  
  127. In demo.js I'll require Vue and a dependency we'll use in the next step. We'll also create /demoComponents/app.vue and require that as well.
  128.  
  129. Finally we'll reference our app.vue require as a component so our `<app></app>` tag will come alive.
  130.  
  131. !! Show off all new files, especially the .vue file structure !!
  132.  
  133. Things are going to accelerate at this point. Hold on tight.
  134.  
  135. # Step 19
  136. We'll use vue-resource to ajax in the data from a laravel route that is serving json
  137.  
  138. !! Show that we do this in the app.vue file, show that we're echoing the json to the view via the json filter !!
  139.  
  140. !! Quick overview of our example data !!
  141.  
  142. # Step 20
  143. Now we have an example component and we're passing in single example's-worth of data. Notice we're passing it in as a property inside of a v-for. This means we'll now have an example.vue file.
  144.  
  145. !! Show that we are requiring the example.vue file inside the app.vue file and adding it to the components object for the app component. !!
  146.  
  147. !! Show off the example.vue file. Note the template is just a bootstrap panel an we're referencing a lot of the data in our example object. Note the example vue definition is very minimal (just a props definition) !!
  148.  
  149. Note we're not rendering the markdown yet.
  150.  
  151. # Step 21
  152. Now we're going to render this markdown. Since the only thing that needs to render markdown is the example component this is where we'll require that dependency (a package called "marked").
  153.  
  154. !! Show how I require marked, set the github flavored markdown option to true and set marked up as a filter (since filters just pass a value into a function and expect a return) !!
  155.  
  156. Voila
  157.  
  158. # Step 22
  159. Now that we have a handle on this nested components thing let's nest another component. Comments! You may notice we had a comments object nested inside our example object, we'll be using that.
  160.  
  161. This means a new comments.vue file, requiring the file in the example component and adding the component to the example component.
  162.  
  163. There's a lot more going on in this one. We have a click handler on a button to show/hide the comments secction (@click). We have a computed property that will be bound to the text on the button so it toggles as we toggle the comments field.
  164.  
  165. !! Show how we're not doing any .toggle() style jquery stuff. That's oldschool. We want our view to reflect our model. So if we want a toggleable comments section we should have a piece of data that reflects this state. That piece of data is called showHide and it defaults to false. !!
  166.  
  167. !! Note the v-if that will throw a message to the view if there are no comments to view !!
  168.  
  169. # Step 23
  170. Let's make it so we can show a pageful of examples and expand the ones we want to view. We'll get rid of our json output because it is cluttering our view at this point and we get what's going on. We will follow a similar patter with the show/hide toggling that we used on the comments section. I want to pass in a boolean as a property to the `<example></example>` tag so I will need to do some validation on this incoming property. If I don't a true or a false in that attribute will come through as a string. I had a typo in this step, I'm fixing that below. It still worked but for all the wrong reasons, it would have caused issues downt he road.
  171. ```
  172. showhide: {
  173. type: Boolean,
  174. coerce: function(val){
  175. return "true" == val;
  176. },
  177. default: true
  178. }
  179. ```
  180.  
  181. !! Make a note of the showHideGlyph computed property, handy for updating the class on the glyphicon. Also note I'm hiding the comments button by traversing to the $parent object and seeing if the parent is shown/hidden !!
  182.  
  183. # Step 24
  184. Pagination is fun, isn't it? I'm going to use laravel to report the number of pages I should expect and stick that into a property attribute. I'll validate this as an integer and use it to limit my pagination links. I've also created a `<pagelinks></pagelinks>` component.
  185.  
  186. I do some simple math to figure out my bounds and then I render the view based on these bounds.
  187.  
  188. Note: I'm actually using the `<style></style>` block inside pagelinks.vue.
  189.  
  190. I'll dispatch an event up the chain (broadcast is the term for down the chain) and this will be caught by the `<app></app>` component. The app component catches this because it does all the ajaxing and handling of the main examples data payload. Everything then flows down into the child components to render the view.
  191.  
  192. !! Show off the computed properties and how they're used to generate the view !!
  193.  
  194. !! Walk everyone through the event and how I'm grabbing new data based on this !!
  195.  
  196. # Step 25
  197. First and Last page links. Just adding another conditional set of page links that will go to either the first or the last page. A little css in the `<style></style>` block is used to accomplish this.
  198.  
  199. Voila, we have the viewing portion of our example.io site.
  200.  
  201. # POST DEMONSTRATION EXAM
  202. ### Q: How many times did I misspell "example"?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement