Vue.js: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
→‎Templates: Copyedit. Resolve neutrality issues
Line 15: Line 15:
| website = {{URL|https://vuejs.org}}
| website = {{URL|https://vuejs.org}}
}}
}}
'''Vue.js''' (commonly referred to as '''Vue'''; pronounced {{IPA|{{IPAc-en|v|j|uː}}}}, like '''view''') is an [[Open-source software|open-source]] [[JavaScript framework]] for building [[user interface]]s and [[single-page application]]s.<ref>{{Cite web |url = https://vuejs.org/v2/guide/#What-is-Vue-js |title = Introduction — Vue.js |access-date = 2017-03-11 |language = en }}</ref>
'''Vue.js''' (commonly referred to as '''Vue'''; pronounced {{IPA|{{IPAc-en|v|j|uː}}}}, like '''view''') is an [[Open-source software|open-source]] [[JavaScript framework]] for building [[user interface]]s and [[single-page application]]s.{{refn|<ref>{{cite book |last1=Macrae |first1=Callum |title=Vue.js: Up and Running: Building Accessible and Performant Web Apps |date=2018 |publisher=[[O'Reilly Media]] |isbn=9781491997215 |url=https://books.google.com/books?id=bJpNDwAAQBAJ |language=en}}</ref><ref>{{cite book |last1=Nelson |first1=Brett |title=Getting to Know Vue.js: Learn to Build Single Page Applications in Vue from Scratch |date=2018 |publisher=[[Apress]] |isbn=9781484237816 |url=https://books.google.com/books?id=mTpsDwAAQBAJ |language=en}}</ref><ref>{{cite book |last1=Yerburgh |first1=Edd |title=Testing Vue.js Applications |date=2019 |publisher=[[Manning Publications]] |isbn=9781617295249 |url=https://books.google.com/books?id=7-FAtAEACAAJ |language=en}}</ref><ref>{{cite book |last1=Freeman |first1=Adam |title=Pro Vue.js 2 |date=2018 |publisher=[[Apress]] |isbn=9781484238059 |url=https://books.google.com/books?id=HQFuDwAAQBAJ |language=en}}</ref><ref>{{cite book |last1=Franklin |first1=Jack |last2=Wanyoike |first2=Michael |last3=Bouchefra |first3=Ahmed |last4=Silas |first4=Kingsley |last5=Campbell |first5=Chad A. |last6=Jacques |first6=Nilson |last7=Omole |first7=Olayinka |last8=Mulders |first8=Michiel |title=Working with Vue.js |date=2019 |publisher=[[SitePoint]] |isbn=9781492071440 |url=https://books.google.com/books?id=OKScDwAAQBAJ |language=en}}</ref><ref>{{Cite web |url = https://vuejs.org/v2/guide/#What-is-Vue-js |title = Introduction — Vue.js |access-date = 2017-03-11 |language = en }}</ref>}}


== Overview ==
== Overview ==

Revision as of 13:31, 9 August 2019

Vue.js
Original author(s)Evan You
Initial releaseFebruary 2014; 10 years ago (2014-02)[1]
Stable release
2.6.10 / March 20, 2019; 5 years ago (2019-03-20)[2]
Repository
Written inJavaScript
Size30.67 KB production
279 KB development
TypeJavaScript framework
LicenseMIT License[3]
Websitevuejs.org

Vue.js (commonly referred to as Vue; pronounced /vj/, like view) is an open-source JavaScript framework for building user interfaces and single-page applications.[10]

Overview

Vue.js features an incrementally adoptable architecture that focuses on declarative rendering and component composition. Advanced features required for complex applications such as routing, state management and build tooling are offered via officially maintained supporting libraries and packages.[11]

History

Vue was created by Evan You after working for Google using AngularJS in a number of projects. He later summed up his thought process: "I figured, what if I could just extract the part that I really liked about Angular and build something really lightweight."[12] The first source code commit to the project was dated July 2013, and Vue was first released the following February, in 2014.

Versions

Version Release date Title
2.6 2019 Feb 04 Macross
2.5 2017 Oct 13 Level E
2.4 2017 Jul 13 Kill la Kill
2.3 2017 Apr 27 JoJo's Bizarre Adventure
2.2 2017 Feb 26 Initial D
2.1 2016 Nov 22 Hunter X Hunter
2.0 2016 Sep 30 Ghost in the Shell
1.0 2015 Oct 27 Evangelion
0.12 2015 Jun 12 Dragon Ball
0.11 2014 Nov 07 Cowboy Bebop
0.10 2014 Mar 23 Blade Runner
0.9 2014 Feb 25 Animatrix
0.8 2014 Jan 27 -
0.7 2013 Dec 24 -
0.6 2013 Dec 08 VueJS

Features

Templates

Vue uses an HTML-based template syntax that allows binding the rendered DOM to the underlying Vue instance's data. All Vue templates are valid HTML that can be parsed by specification-compliant browsers and HTML parsers. Vue compiles the templates into virtual DOM render functions. A virtual Document Object Model (or “DOM”) allows Vue to render components in its memory before updating the browser. Combined with the reactivity system, Vue is able to calculate the minimal number of components to re-render and apply the minimal amount of DOM manipulations when the app state changes.

Vue users can use template syntax or choose to directly write render functions using JSX.[13] Render functions allow application to be built from software components.[14]

Reactivity

Vue features a reactivity system that uses plain JavaScript objects and optimized re-rendering. Each component keeps track of its reactive dependencies during its render, so the system knows precisely when to re-render, and which components to re-render.[15]

Components

Vue components extend basic HTML elements to encapsulate reusable code. At a high level, components are custom elements to which the Vue’s compiler attaches behavior. In Vue, a component is essentially a Vue instance with pre-defined options.[16] The code snippet below contains an example of a Vue component. The component presents a button and prints the number of times the button is clicked:

<div id="tuto">
	<button-clicked v-bind:initial-count="0"></button-clicked>
</div>

<script>
Vue.component('button-clicked', {
  props: [ "initialCount" ],
  data: () => ({
    count: 0,
  }),
  template: `<button v-on:click="onClick">Clicked {{ count }} times</button>`,
  computed: {
    countTimesTwo() {
      return this.count * 2;
    }
  },
  watch: {
    count(newValue, oldValue) {
      console.log(`The value of count is changed from ${oldValue} to ${newValue}.`);
    }
  },
  methods: {
    onClick() {
        this.count += 1;
    }
  },
  mounted() {
    this.count = this.initialCount;
  }
});

new Vue({
  el: '#tuto',
});
</script>

Transitions

Vue provides a variety of ways to apply transition effects when items are inserted, updated, or removed from the DOM. This includes tools to:

  • Automatically apply classes for CSS transitions and animations
  • Integrate third-party CSS animation libraries, such as Animate.css
  • Use JavaScript to directly manipulate the DOM during transition hooks
  • Integrate third-party JavaScript animation libraries, such as Velocity.js

When an element wrapped in a transition component is inserted or removed, this is what happens:

  1. Vue will automatically sniff whether the target element has CSS transitions or animations applied. If it does, CSS transition classes will be added/removed at appropriate timings.
  2. If the transition component provided JavaScript hooks, these hooks will be called at appropriate timings.
  3. If no CSS transitions/animations are detected and no JavaScript hooks are provided, the DOM operations for insertion and/or removal will be executed immediately on next frame.[17][18]

Routing

A traditional disadvantage of single-page applications (SPAs) is the inability to share links to the exact "sub" page within a specific web page. Because SPAs serve their users only one URL-based response from the server (it typically serves index.html or index.vue), bookmarking certain screens or sharing links to specific sections is normally difficult if not impossible. To solve this problem, many client-side routers delimit their dynamic URLs with a "hashbang" (#!), e.g. page.com/#!/. However, with HTML5 most modern browsers support routing without hashbangs.

Vue provides an interface to change what is displayed on the page based on the current URL path -- regardless of how it was changed (whether by emailed link, refresh, or in-page links). Additionally, using a front-end router allows for the intentional transition of the browser path when certain browser events (i.e. clicks) occur on buttons or links. Vue itself doesn’t come with front-end hashed routing. But the open source "vue-router" package provides an API to update the application's URL, supports the back button (navigating history), and email password resets or email verification links with authentication URL parameters. It supports mapping nested routes to nested components and offers fine-grained transition control. With Vue, developers are already composing applications with small building blocks building larger components. With vue-router added to the mix, components must merely be mapped to the routes they belong to, and parent/root routes must indicate where children should render.[19]

<div id="app">
  <router-view></router-view>
</div>
...

<script>
...
const User = {
  template: '<div>User {{ $route.params.id }}</div>'
}

const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User }
  ]
})
...
</script>

The code above:

  1. Sets a front-end route at websitename.com/user/<id>.
  2. Which will render in the User component defined in (const User...)
  3. Allows the User component to pass in the particular id of the user which was typed into the URL using the $route object's params key: $route.params.id.
  4. This template (varying by the params passed into the router) will be rendered into <router-view></router-view> inside the DOM's div#app.
  5. The finally generated HTML for someone typing in: websitename.com/user/1 will be:
<div id="app">
  <div>
    <div>User 1</div>
  </div>
</div>

[20]

See also

Sources

 This article incorporates text from a free content work. Licensed under MIT License (license statement/permission). Text taken from Vue.js Guide​, Vue.js, .

References

  1. ^ "First Week of Launching Vue.js". Evan You.
  2. ^ "Vue.js Releases". GitHub.
  3. ^ "vue/LICENSE". GitHub. Retrieved 17 April 2017.
  4. ^ Macrae, Callum (2018). Vue.js: Up and Running: Building Accessible and Performant Web Apps. O'Reilly Media. ISBN 9781491997215.
  5. ^ Nelson, Brett (2018). Getting to Know Vue.js: Learn to Build Single Page Applications in Vue from Scratch. Apress. ISBN 9781484237816.
  6. ^ Yerburgh, Edd (2019). Testing Vue.js Applications. Manning Publications. ISBN 9781617295249.
  7. ^ Freeman, Adam (2018). Pro Vue.js 2. Apress. ISBN 9781484238059.
  8. ^ Franklin, Jack; Wanyoike, Michael; Bouchefra, Ahmed; Silas, Kingsley; Campbell, Chad A.; Jacques, Nilson; Omole, Olayinka; Mulders, Michiel (2019). Working with Vue.js. SitePoint. ISBN 9781492071440.
  9. ^ "Introduction — Vue.js". Retrieved 2017-03-11.
  10. ^ [4][5][6][7][8][9]
  11. ^ "Evan is creating Vue.js | Patreon". Patreon. Retrieved 2017-03-11.
  12. ^ "Between the Wires | Evan You". Between the Wires. 2016-11-03. Archived from the original on 2017-06-03. Retrieved 2017-08-26. {{cite news}}: Unknown parameter |dead-url= ignored (|url-status= suggested) (help)
  13. ^ "Template Syntax — Vue.js". Retrieved 2017-03-11.
  14. ^ "Vue 2.0 is Here!". The Vue Point. 2016-09-30. Retrieved 2017-03-11.
  15. ^ "Reactivity in Depth — Vue.js". Retrieved 2017-03-11.
  16. ^ "Components — Vue.js". Retrieved 2017-03-11.
  17. ^ "Transition Effects — Vue.js". Retrieved 2017-03-11.
  18. ^ "Transitioning State — Vue.js". Retrieved 2017-03-11.
  19. ^ "Routing — Vue.js". Retrieved 2017-03-11.
  20. ^ You, Evan. "Vue Nested Routing (2)". Vue Home Page (subpage). Retrieved 10 May 2017.

External links