The content of this article is about the comparison between using Angularjs and Vue.js. Now I share it with you. Friends in need can refer to it
First of all, let’s briefly talk about their respective characteristics in theory, and then use a few small examples to illustrate them.
progressive framework for building user interfaces. Unlike other heavyweight frameworks, Vue adopts a bottom-up incremental development design. Vue's core library only focuses on the view layer, and is very easy to learn and integrate with other libraries or existing projects. On the other hand, Vue is fully capable of driving complex single-page applications developed using single-file components and Vue ecosystem-supported libraries. The goal of Vue.js is to implement responsive data binding
andcomposed view components through the simplest possible API.
(1) Modularization. Currently, the hottest way is to directly use ES6 modularity in the project and combine it with Webpack for project packaging.vue is very small. After compression, the min source code is 72.9kb. After gzip compression, it is only 25.11kb. It is 144kb compared to Angular. You can use it by yourself with the required library plug-ins, similar to the routing plug-in (Vue-router ), Ajax plug-in (vue-resource, axios), etc.
##angular.js:Dirty value check
angular.js uses dirty value detection to compare whether the data has changed to decide whether to update the view. The simplest way is to regularly poll to detect data changes through setInterval(). Of course, Google will not So low, Angular only enters dirty value detection when a specified event is triggered, roughly as follows:vue: Data hijacking
vue.js uses data hijacking combined with the publisher-subscriber model to hijack each property through Object.defineProperty() The setters and getters publish messages to subscribers when data changes, triggering corresponding listening callbacks. https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/definePropertydefinePropertyThe code is directly belowThe first is of course Hello Worldvue<p id="app"> {{ message }} </p> new Vue({ el: '#app', data: { message: 'Hello Vue.js!' } })
<p ng-app="myApp" ng-controller="myCtrl"> {{message}} </p> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.message = "Hello world"; });
<p id="app"> <p>{{ message }}</p> <input v-model="message"> </p> new Vue({ el: '#app', data: { message: 'Hello Vue.js!' } })
<p ng-app="myApp" ng-controller="myCtrl"> <p>{{message}}</p> <input ng-model="message"> </p> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.message = "Hello world!"; });
<p id="app"> <ul> <li v-for="name in names"> {{ name.first }} </li> </ul> </p> new Vue({ el: '#app', data: { names: [ { first: 'summer', last: '7310' }, { first: 'David', last:'666' }, { first: 'Json', last:'888' } ] } })
<p ng-app="myApp" ng-controller="myCtrl"> <li ng-repeat="name in names">{{name.first}}</li> </p> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.names = [ { first: 'summer', last: '7310' }, { first: 'David', last:'666' }, { first: 'Json', last:'888' } ] });
<ul> <li v-for="item in list"> <a :href="item.url">{{item.title}}</a> </li> </ul>
<p class="item" ng-repeat="news in newsList"> <a ng-href="#/content/{{news.id}}"> <img ng-src="{{news.img}}" /> <p class="item-info"> <h3 class="item-title">{{news.title}}</h3> <p class="item-time">{{news.createTime}}</p> </p> </a> </p>
<p id="app"> <p>{{ message }}</p> <button v-on:click="reverseMessage">Reverse Message</button> </p> new Vue({ el: '#app', data: { message: 'Hello Vue.js!' }, methods: { reverseMessage: function () { this.message = this.message.split('').reverse().join('') } } })
<p ng-app="myApp" ng-controller="myCtrl"> <p>{{ message }}</p> <button ng-click="reverseMessage()">Reverse Message</button> </p> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.message = "Hello world!"; $scope.reverseMessage = function() { this.message = this.message.split('').reverse().join('') } });
相关推荐:
The above is the detailed content of Comparison using Angularjs and Vue.js. For more information, please follow other related articles on the PHP Chinese website!