
Vue.js uses a DOM-based templating implementation. This means that all Vue.js templates are essentially valid, parsable HTML enhanced with some special attributes. Keep that in mind, since this makes Vue templates fundamentally different from string-based templates.
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:
We can use the v-on directive to listen to DOM events and run some JavaScript when they’re triggered.
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, Vue provides special enhancements when v-bind is used with class and style. In addition to strings, the expressions can also evaluate to objects or arrays.
Since components are reusable Vue instances, they accept the same options as new Vue, such as data, computed, watch, methods, and lifecycle hooks. The only exceptions are a few root-specific options like el.
The v- prefix serves as a visual cue for identifying Vue-specific attributes in your templates. This is useful when you are using Vue.js to apply dynamic behavior to some existing markup, but can feel verbose for some frequently used directives. At the same time, the need for the v- prefix becomes less important when you are building a SPAwhere Vue.js manages every template. Therefore, Vue.js provides special shorthands for two of the most often used directives, v-bind and v-on:
Vue CLI aims to be the standard tooling baseline for the Vue ecosystem. It ensures the various build tools work smoothly together with sensible defaults so you can focus on writing your app instead of spending days wrangling with configurations. At the same time, it still offers the flexibility to tweak the config of each tool without the need for ejecting.
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 to enhance certain views. In more complex projects however, or when your frontend is entirely driven by JavaScript, these disadvantages become apparent:
Global definitions force unique names for every component
String templates lack syntax highlighting and require ugly slashes for multiline HTML
No CSS support means that while HTML and JavaScript are modularized into components, CSS is conspicuously left out
No build step restricts us to HTML and ES5 JavaScript, rather than preprocessors like Pug (formerly Jade) and Babe
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 to enhance certain views. In more complex projects however, or when your frontend is entirely driven by JavaScript, these disadvantages become apparent:
Global definitions force unique names for every component
String templates lack syntax highlighting and require ugly slashes for multiline HTML
No CSS support means that while HTML and JavaScript are modularized into components, CSS is conspicuously left out
No build step restricts us to HTML and ES5 JavaScript, rather than preprocessors like Pug (formerly Jade) and Babe
In this video, I will show you to manage vue state using gloabl pattern. You will create a separate custom store.js file to handle the state
In-template expressions are very convenient, but they are meant for simple operations. Putting too much logic in your templates can make them bloated and hard to maintain.
We will add new record in local store. I will show you how to create a new mutation to save record
In this video, we will implement the edit record feature. I will show you how to set the data to input element
In this video, we will update and delete the task from the local store in vue
In this video, I will show you to divide static hmtl into vuejs components.In a Vue application, we don’t want all of our data, methods, computed properties, etc. living on the root instance. Over time, that would become unmanageable. Instead, we’ll want to break up our code into modular pieces so that it is easier and more flexible to work with.
We can use the v-for directive to render a list of items based on an array. The v-fordirective 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:
Unlike components and props, event names don’t provide any automatic case transformation. Instead, the name of an emitted event must exactly match the name used to listen to that event. For example, if emitting a camelCased event name:
this.$emit('myEvent')
Listening to the kebab-cased version will have no effect:
<my-component v-on:my-event="doSomething"></my-component>
Unlike components and props, event names don’t provide any automatic case transformation. Instead, the name of an emitted event must exactly match the name used to listen to that event. For example, if emitting a camelCased event name:
You can pass data through the “props” to the child components. That’s fine. But what if you need to communicate with some other component which is not a child component? Things are getting complicated there. But not anymore. Let’s take advantage of the event mechanism in vue.
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 snapshot export / import.
Sometimes we may need to compute derived state based on store state, for example filtering through a list of items and counting them:
The only way to actually change state in a Vuex store is by committing a mutation. Vuex mutations are very similar to events: each mutation has a string type and a handler. The handler function is where we perform actual state modifications, and it will receive the state as the first argument:
The only way to actually change state in a Vuex store is by committing a mutation. Vuex mutations are very similar to events: each mutation has a string type and a handler. The handler function is where we perform actual state modifications, and it will receive the state as the first argument:
Components are one of the most powerful features of Vue.js. They help you extend basic HTML elements to encapsulate reusable code. At a high level, Components are custom elements that Vue.js’ compiler would attach specified behavior to. In some cases, they may also appear as a native HTML element extended with the special is attribute.
Due to using a single state tree, all state of our application is contained inside one big object. However, as our application grows in scale, the store can get really bloated.
To help with that, Vuex allows us to divide our store into modules. Each module can contain its own state, mutations, actions, getters, and even nested modules - it's fractal all the way down:
Actions are similar to mutations, the differences being that:
Instead of mutating the state, actions commit mutations.
Actions can contain arbitrary asynchronous operations.
Actions are similar to mutations, the differences being that:
Instead of mutating the state, actions commit mutations.
Actions can contain arbitrary asynchronous operations.
In this video, we will create a separate action and mutation for post and delete http request
Sometimes we may need to compute derived state based on store state, for example filtering through a list of items and counting them: If more than one component needs to make use of this, we have to either duplicate the function, or extract it into a shared helper and import it in multiple places - both are less than ideal.
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 for some edge cases.
v-model will ignore the initial value, checked or selected attributes found on any form elements. It will always treat the Vue instance data as the source of truth. You should declare the initial value on the JavaScript side, inside the data option of your component.
For languages that require an IME (Chinese, Japanese, Korean etc.), you’ll notice that v-model doesn’t get updated during IME composition. If you want to cater for these updates as well, use input event instead.
Form validation is natively supported by the browser, but sometimes different browsers will handle things in a manner which makes relying on it a bit tricky. Even when validation is supported perfectly, there may be times when custom validations are needed and a more manual, Vue-based solution may be more appropriate. Let’s begin with a simple example.
For the second example, the second text field (age) was switched to email which will be validated with a bit of custom logic. The code is taken from the StackOverflow question, How to validate email address in JavaScript?. This is an awesome question because it makes your most intense Facebook political/religious argument look like a slight disagreement over who makes the best beer. Seriously - it’s insane. Here is the HTML, even though it’s really close to the first example.
For radio, checkbox and select options, the v-model binding values are usually static strings (or booleans for checkbox):
While this cookbook entry focused on doing form validation “by hand”, there are, of course, some great Vue libraries that will handle a lot of this for you. Switching to a prepackage library may impact the final size of your application, but the benefits could be tremendous. You have code that is (most likely) heavily tested and also updated on a regular basis. Some examples of form validation libraries for Vue include:
vuelidate
VeeValidate
Vue Router is the official router for Vue.js. It deeply integrates with Vue.js core to make building Single Page Applications with Vue.js a breeze. Features include:
Nested route/view mapping
Modular, component-based router configuration
Route params, query, wildcards
View transition effects powered by Vue.js' transition system
Fine-grained navigation control
Links with automatic active CSS classes
HTML5 history mode or hash mode, with auto-fallback in IE9
Customizable Scroll Behavior
Very often we will need to map routes with the given pattern to the same component. For example we may have a User component which should be rendered for all users but with different user IDs. In vue-router we can use a dynamic segment in the path to achieve that:
Real app UIs are usually composed of components that are nested multiple levels deep. It is also very common that the segments of a URL corresponds to a certain structure of nested components,
Aside from using <router-link> to create anchor tags for declarative navigation, we can do this programmatically using the router's instance methods.
As the name suggests, the navigation guards provided by vue-router are primarily used to guard navigations either by redirecting it or canceling it. There are a number of ways to hook into the route navigation process: globally, per-route, or in-component.
Remember that params or query changes won't trigger enter/leave navigation guards. You can either watch the $route object to react to those changes, or use the beforeRouteUpdate in-component guard.
Nuxt.js is a free and open source web application framework based on Vue.js, Node.js, Express.js, Webpack and Babel.js. The framework is advertised as "meta-framework for universal applications
To get started quickly, the Nuxt.js team has created scaffolding tool create-nuxt-app.
Make sure you have npx installed (npx is shipped by default since NPM 5.2.0)
$ npx create-nuxt-app <project-name>
Or with yarn:
yarn create nuxt-app <my-project>
The default Nuxt.js application structure is intended to provide a great starting point for both small and large applications. Of course, you are free to organize your application however you like.
Using a store to manage the state is important to every big application, that's why Nuxt.js implements Vuex in its core.
Nuxt.js automatically generates the vue-router configuration based on your file tree of Vue files inside the pages directory.
In this video, you are going to learn how to add navbar using element ui nav-menu component
In this video, we will use v-for directive to render all the list items in the component
It Integrate information in a card container.
The substr() method returns the part of a string between the start index and a number of characters after it.
Get a full fake REST API with zero coding in less than 30 seconds (seriously)
The fetch method is used to fill the store before rendering the page, it's like the asyncDatamethod except it doesn't set the component data.
Type: Function
The fetch method, if set, is called every time before loading the component (only for page components). It can be called from the server-side or before navigating to the corresponding route.
The fetch method receives the context object as the first argument, we can use it to fetch some data and fill the store. To make the fetch method asynchronous, return a Promise, Nuxt.js will wait for the promise to be resolved before rendering the component.
In this video, we will fetch a single record from server by sending http get request to server. After fetching single record, we will save the record to vuex store
Form consists of input, radio, select, checkbox and so on. With form, you can collect, verify and submit data.
Just add the rules attribute for Form component, pass validation rules, and set prop attribute for Form-Item as a specific key that needs to be validated. See more information at async-validator.
In this video, we will send asynchronous request from Nuxt project to backend server.
You will learn how to send Aysnc request from Nuxt application to backend server. In this video, we will update the post
In this video, we will send the http delete request from nuxt application using fetch method
What is Vue.Js?
Vue.js (commonly referred to as Vue; pronounced /vjuː/, like view) is an open-source JavaScript framework for building user interfaces.
Vue.js is yet another JavaScript UI library that is making waves and has growing support from the community. If you have an upcoming project and are wondering which tool to choose, you can give Vue a try.
Vue is considerably easy to learn and you can get started with it in just 10 minutes (actually, that is what this article is going to help you do). But first, let’s have a quick look at why you should even give Vue a try.
Why Vue.js?
When comparing it with its competitors, including Angular, React, Ember, Aurelia, etc., Vue boasts of beating some of them in certain aspects. These aspects include simple API, size, performance, learning curve, etc. You can have a look at these comparisons on the official documentation.
What you will learn in this course ?
Setting up a Development Environment and Workflow
The Basics (including the basic Syntax, Understanding Templates and much more!)
Interacting with DOM (Rendering Lists, Conditionally attaching/ detaching Elements ...)
Using Components (and what Components are to begin with)
Binding to Form Input
State Management with VueJs
How to create an awesome Single-Page-Application (SPA) with Routing
Build Server Rendered App with NuxtJs
In this course you are going to build 6 small web applications with Vue.js, Vuex and Nuxt
Vote App - Learn the Vue basics by building vote application
Todo App - In this module you will build a basic Todo App with VueJs
Kanban Board Application - In this module you will build a basic project management app using Vue components
Shopping Cart Server with Vuex - In this course, you will master the Vuex fundamentals by building shopping cart feature
Build a conference form - In this module you will master the forms fundamentals of VueJs
Blog App - You will learn how to build server rendered application with Vuex and NuxtJs