SwissJS 2015 Lighting Talk – Raphaël Saunier (@RaphaelSaunier)
Large libraries are not always adequate for:
$.problem() ?
“[…] Vue.js core intends to stay as a no-frills, drop-in view layer library, and that will not change”
All of this with a familiar syntax, a comprehensive documentation, friendly error messages and
great performance!
* Minified (~22KB gzipped)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue.js</title>
<script src="vue.js">
</script>
</head>
<body>
<div id="selector">
<h1>{{message}}</h1>
</div>
</body>
</html>
// Define a plain JSON
// object to hold the data
var data = {
message: "Hello"
};
// Instantiate Vue on an element
new Vue({
el: "#selector",
data: data
})
// Works since getters/setters
// are now proxied
data.message = "Hi";
<div id="selector">
<input type="text"
v-model="name">
<h1 v-if="name">
{{message | uppercase}}
</h1>
</div>
new Vue({
el: "#selector",
data: {
name: ""
},
computed: {
message: function(){
return "Hello, " + name + "!";
}
}
});
<div id="selector">
<input type="text" ng-model="name">
<h1 ng-if="name">
<%= message %>
</h1>
</div>
// I'd like delimiters that are more difficult to type
Vue.config.delimiters: ['<%=', '%>'];
// I'd like to have the performance of Backbone Views
Vue.config.async = false
// I'd like to pretend it's Angular
Vue.config.prefix = "ng-";
var Controller = Vue.extend({
$scope: this.data // (…don't do that, it's silly)
});
<ul id="selector">
<li v-repeat="person: people"
v-on="click: greet">
{{person.name}}
</li>
</ul>
var rofl = new Vue({
el: "#selector",
data: {
people: [{
name: "Bruno",
job: "Kameramann"
} /* ... */]
},
methods: {
greet: function(person){
alert(`Ich bin ${person.name},
ich bin der ${person.job}!`);
}
}
});
Visit vuejs.org/examples for more examples
Should you go all in on Vue.js?
Probably not.
Should you use Vue.js to replace
jQuery or Backbone Views?
Probably!
vue + vue-router > jquery + backbone + underscore + rivets + marionette
JS libraries come and go, and therefore it makes
sense to invest one's time wisely.
With Vue you‘ll: