Difference between revisions of "VueJS"
(→Notes) |
|||
Line 2: | Line 2: | ||
After a lot of looking around I've settled on the [https://vuejs.org/v2/guide Vue2] framework which is similar to [https://facebook.github.io/react/ React] but has a simpler learning curve (it's practically as simple as [[jQuery]] to get started with by just including the script and writing code, or the next step, building with the [https://github.com/vuejs-templates/simple simple] template) while also scaling very well - in fact in virtually all tests it's shown to be faster and more scalable than React. Another popular option is [https://angularjs.org/ AngularJS] which shares a lot of similarities with Vue - both React and Angular have served as strong inspiration for the development of Vue. As is the case for React, Angular has a steep learning curve which is one of the main reasons for me to prefer Vue - I like the idea of an efficient minimalist system that is very easy to get started with and yet also very scalable. Angular is also very "opinionated" which means that it dictates a lot about the way you should structure you're application. Vue is much more flexible, but also offers the [https://github.com/vuejs-templates/webpack Webpack] template if you want an entire tool-chain and structure predefined for you. Angular2 is much more efficient, but Vue still beats it, and in terms of size, Vue's 23KB is hard to beat (actually it is beatable though - RiotJS is only 10KB, but I feel that the massive efficiency gains of Vue are worth the extra few KB). | After a lot of looking around I've settled on the [https://vuejs.org/v2/guide Vue2] framework which is similar to [https://facebook.github.io/react/ React] but has a simpler learning curve (it's practically as simple as [[jQuery]] to get started with by just including the script and writing code, or the next step, building with the [https://github.com/vuejs-templates/simple simple] template) while also scaling very well - in fact in virtually all tests it's shown to be faster and more scalable than React. Another popular option is [https://angularjs.org/ AngularJS] which shares a lot of similarities with Vue - both React and Angular have served as strong inspiration for the development of Vue. As is the case for React, Angular has a steep learning curve which is one of the main reasons for me to prefer Vue - I like the idea of an efficient minimalist system that is very easy to get started with and yet also very scalable. Angular is also very "opinionated" which means that it dictates a lot about the way you should structure you're application. Vue is much more flexible, but also offers the [https://github.com/vuejs-templates/webpack Webpack] template if you want an entire tool-chain and structure predefined for you. Angular2 is much more efficient, but Vue still beats it, and in terms of size, Vue's 23KB is hard to beat (actually it is beatable though - RiotJS is only 10KB, but I feel that the massive efficiency gains of Vue are worth the extra few KB). | ||
+ | |||
+ | == General == | ||
+ | The general idea behind Vue is to "vueify" elements by constructing a new Vue instance with the ''el'' property selecting the node(s), which similar to [[jQuery]]'s ''$("#foo")'' concept. | ||
+ | <source lang="js"> | ||
+ | new Vue({ | ||
+ | el: "#foo" | ||
+ | }); | ||
+ | </source> | ||
+ | This is not a very useful example though, the most simple functional "Hello World!" example is: | ||
+ | <source lang="html"> | ||
+ | <div id="foo">{{bar}}</div> | ||
+ | </source> | ||
+ | <source lang="js"> | ||
+ | var app = new Vue({ | ||
+ | el: "#foo" | ||
+ | data: { | ||
+ | bar: "Hello World!" | ||
+ | } | ||
+ | }); | ||
+ | </source> | ||
+ | Here the element that the Vue instance binds to has a mustache-style template parameter specified in it called ''bar''. The Vue instance binds to it with the ''#foo'' selector in its ''el'' property, and creates a persistent connection between the ''bar'' parameter in the element and the ''bar'' sub-property of its ''data'' property. The ''bar'' property of the view instance can be accessed or changed via the instance with ''app.bar'' and any updates to it will be immediately reflected in the HTML element. | ||
+ | |||
+ | == Component model == | ||
+ | |||
== Notes == | == Notes == |
Revision as of 14:27, 26 February 2017
It's becoming more and more critical in recent months that I get up to speed with a decent JavaScript framework that supports Single Page Applications. I've built a few simple SPA's before one without a framework, and the others using Backbone. Backbone is getting a bit dated now, and I need to build an SPA that is considerably more complicated than those I've made before.
After a lot of looking around I've settled on the Vue2 framework which is similar to React but has a simpler learning curve (it's practically as simple as jQuery to get started with by just including the script and writing code, or the next step, building with the simple template) while also scaling very well - in fact in virtually all tests it's shown to be faster and more scalable than React. Another popular option is AngularJS which shares a lot of similarities with Vue - both React and Angular have served as strong inspiration for the development of Vue. As is the case for React, Angular has a steep learning curve which is one of the main reasons for me to prefer Vue - I like the idea of an efficient minimalist system that is very easy to get started with and yet also very scalable. Angular is also very "opinionated" which means that it dictates a lot about the way you should structure you're application. Vue is much more flexible, but also offers the Webpack template if you want an entire tool-chain and structure predefined for you. Angular2 is much more efficient, but Vue still beats it, and in terms of size, Vue's 23KB is hard to beat (actually it is beatable though - RiotJS is only 10KB, but I feel that the massive efficiency gains of Vue are worth the extra few KB).
Contents
General
The general idea behind Vue is to "vueify" elements by constructing a new Vue instance with the el property selecting the node(s), which similar to jQuery's $("#foo") concept.
new Vue({
el: "#foo"
});
This is not a very useful example though, the most simple functional "Hello World!" example is:
<div id="foo">{{bar}}</div>
var app = new Vue({
el: "#foo"
data: {
bar: "Hello World!"
}
});
Here the element that the Vue instance binds to has a mustache-style template parameter specified in it called bar. The Vue instance binds to it with the #foo selector in its el property, and creates a persistent connection between the bar parameter in the element and the bar sub-property of its data property. The bar property of the view instance can be accessed or changed via the instance with app.bar and any updates to it will be immediately reflected in the HTML element.
Component model
Notes
- It may be good to use Weex templates for cross-platform native rendering
- "Vue has a clearer separation between directives and components. Directives are meant to encapsulate DOM manipulations only, while components are self-contained units that have their own view and data logic. In Angular, there’s a lot of confusion between the two.
- Cleaning up on transitions
- Properties in routes
See also
- Awesome Vue - big list of examples and tutorials
- VueComponents.com - a lot of nice clear examples
- The Vue router
- Building large-scale apps