Category Archives: vuejs

Vuejs: Vuex

[Fuente:] Vuex is a state management pattern + library for Vue.js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion. It also integrates with Vue’s official devtools extension to provide advanced features such as zero-config time-travel debugging and state […]

Vuejs: Unit testing

[Fuente:] Unit Testing Vue CLI has built-in options for unit testing with Jest or Mocha that works out of the box. We also have the official Vue Test Utils which provides more detailed guidance for custom setups. Simple Assertions You don’t have to do anything special in your components to make them testable. Export the raw options: <template> <span>{{ message }}</span> </template> […]

Vuejs: Typescript support

[Fuente:] TypeScript Support Vue CLI provides built-in TypeScript tooling support. Official Declaration in NPM Packages A static type system can help prevent many potential runtime errors, especially as applications grow. That’s why Vue ships with official type declarations for TypeScript – not only in Vue core, but also for vue-router and vuex as well. Since these are published on NPM, and the latest TypeScript […]

Vuejs: Single File Componentes & Vuejs CLI

[Fuente:] Single File Components Introduction Watch a free video lesson on Vue School In many Vue projects, global components will be defined using Vue.component, followed by new Vue({ el: ‘#container’ }) to target a container element in the body of every page. This can work very well for small to medium-sized projects, where JavaScript is only used […]

Vuejs: Components Basics

[Fuente:] Components Basics Watch a free video course on Vue School Base Example Here’s an example of a Vue component: // Define a new component called button-counter Vue.component(‘button-counter’, { data: function () { return { count: 0 } }, template: ‘<button v-on:click=”count++”>You clicked me {{ count }} times.</button>’ }) Components are reusable Vue instances […]

Vuejs: Form input bindings

[Fuente:] Form Input Bindings Basic Usage You can use the v-model directive to create two-way data bindings on form input, textarea, and select elements. It automatically picks the correct way to update the element based on the input type. Although a bit magical, v-model is essentially syntax sugar for updating data on user input events, plus special care […]

Vuejs: Event handling

[Fuente:] Event Handling Listening to Events We can use the v-on directive to listen to DOM events and run some JavaScript when they’re triggered. For example: <div id=”example-1″> <button v-on:click=”counter += 1″>Add 1</button> <p>The button above has been clicked {{ counter }} times.</p> </div> var example1 = new Vue({ el: ‘#example-1’, data: { counter: 0 } […]

Vuejs: List Rendering

[Fuente:] List Rendering Mapping an Array to Elements with v-for We can use the v-for directive to render a list of items based on an array. The v-for directive requires a special syntax in the form of item in items, where items is the source data array and item is an alias for the array element being iterated on: <ul id=”example-1″> <li v-for=”item in items”> {{ […]

Vuejs: conditional rendering

[Fuente:] Conditional Rendering v-if The directive v-if is used to conditionally render a block. The block will only be rendered if the directive’s expression returns a truthy value. <h1 v-if=”awesome”>Vue is awesome!</h1> It is also possible to add an “else block” with v-else: <h1 v-if=”awesome”>Vue is awesome!</h1> <h1 v-else>Oh no 😢</h1> Conditional Groups with v-if on <template> Because v-if is a directive, […]

Vuejs: class and style bindings

[Fuente:] Class and Style Bindings A common need for data binding is manipulating an element’s class list and its inline styles. Since they are both attributes, we can use v-bind to handle them: we only need to calculate a final string with our expressions. However, meddling with string concatenation is annoying and error-prone. For this reason, […]