#emberjs tutorials
Explore tagged Tumblr posts
Link
"Scaling your Mongo instance is frequently needed and there are various methods you can use to improve scalability on your system which includes sharding and replication. Each of these allows you to spread your database across different servers but they work differently". Reblog with caption 🙃
#angularjs tutorials#advance angularjs tutorials#advance nodejs tutorials#nodejs tutorials#mongodb tutorials#reactjs tutorials#vuejs tutorials#emberjs tutorials#meteorjs tutorials#html5 tutorials#css tutorials#node
0 notes
Text
#emberjs#emberjstutorial#emberjsoverview#php#php tutorial#phptutorialpoints#javascript#javascript framework#javascripttutorial
0 notes
Text
List of Top JavaScript Frameworks 2020 For Front End Development
JavaScript is defining the future of the tech world with its wide genre of competent frameworks, which are capable of accelerating the development of applications in many ways. How to choose a certain framework in JavaScript is based on the company’s goals, project requirements and how certain frameworks can be used in different scenarios.
JavaScript, one of the most surreal and beautiful programming languages, enwrapped by the intriguing fact that even though it is named “Java” Script, it doesn’t have any association with Java. In mid-1995, when JavaScript came into existence it was disguised as the name Mocha and later it was named as “LiveScript” and when Netscape and Sun did a license agreement it was finally renamed to “JavaScript”. Nobody had even imagined in its initial form that it would be such a revolutionary programming language and would be entitled as one of the major languages to learn. The world is pacing fast with the ever-changing technology and programming languages being the pillar of technology. JavaScript is surely defining the future with its compelling and competent frameworks.
What are the Frameworks?
In general, a framework is a prototype or conceptual structure intended to serve as a support or guide for the building of something that expands the structure into something useful. According to Wikipedia ” A software framework is an abstraction in which software providing generic functionality can be selectively changed by additional user-written code, thus providing application-specific software.”
JavaScript web frameworks are cheat codes for quick web application development. They serve as a skeletal frame for single page application development and allows developers to worry less about code structure or maintenance and help them in focusing more on the creation of complex interface elements and expand opportunities of JS and plain HTML.
So, Which frameworks of JavaScript are most popular and why?
Below is the list of a few Javascript frameworks:
1. AngularJS- AngularJS is an open-source framework used in frontend and is maintained by Google. It is mainly used to subside and sort the problems encountered while creating single-page applications usually have, as it simplifies both development and testing of such application by providing a framework for client-side model view controller (MVC) and model view-view model (MVVM) architectures. For now, it is known to be the most used JavaScript framework for single-page applications and have the largest community of developers.
2. ReactJS- ReactJS camouflage itself to be JS framework but it is more of an open-source JS library, which has huge names like Facebook and Instagram behind it. React was built by a software engineer at Facebook. In 2011, it was first deployed on Facebook’s newsfeed and later on Instagram in 2012. React Js emerges in an ecosystem of complete frameworks, but it’s just the view. In MVC(Mobile-View-Controller) pattern, React.js acts as “V” and can be smoothly integrated with any architecture.
A fully functional dynamic application can’t be built with React alone. Recently, On April 18th 2017, Facebook announced a new core algorithm of React framework library for building user interface named React Fiber, which is said to be the foundation for future development and improvement of ReactJS.
3. Ember JS- A few years back, in 2015, EmberJs was considered to be the best framework leaving React and AngularJS behind. It does two-way data binding as same as AngularJS keeping both view and model in sync for all the time. Emberjs is commonly used for complex feature-rich web applications and website. LinkedIn, Netflix, Chipotle, Blue Apron, Nordstrom are one of the few of the top names that have incorporated EmberJS.
What works in its favour is that it is easy to learn and have many tutorials online which helps to learn it with ease.
4. Vue.Js- Vue.js is considered to be one of the best solutions for cross-platform development. The development of Vue.Js is considered by taking the best qualities from Angular, React and Ember such as Vue.js offers two-way data binding (same as in AngularJS), server-side rendering (like in Angular2 and ReactJS), Vue-CLI (backbone tool for quick start) and optional JSX support. and all the altering flaws in prior three.
5. MeteorJS- MeteorJS is a free and open-source framework, which is well-equipped with tons of features for back-end development, front-end rendering, DB(database) management and business logic. Being a full-stack platform, it has the quality that its name suggests which is being fast. If you’re looking to rapidly develop smaller, reactive applications on the Node.js platform, Meteor is definitely an excellent choice.
Due to its modular structure, all the packages and libraries can be used at a high pace. In terms of performance, all the changes in the database are transmitted to the UI in the shortest time possible and in conversely with no evident time losses caused by different languages or server response time.
The consideration of a JavaScript framework is based on the company’s goals, project requirements and how certain frameworks can be used in certain scenarios. JavaScript is portraying the whole new depiction of the future of technology as it backs the prompt development and prototyping.
These frameworks and libraries have already reshaped the way how JS collaborates with HTML and CSS to compile views both in browsers and now even on native platforms.
#java script framework#javascript framework development#javascript development 2020#website development company
2 notes
·
View notes
Text
Getting Started With Nuxt
About The Author
Front-end developer based in Lagos, Nigeria. He enjoys converting designs into code and building things for the web. More about Timi …
Developers often worry about the SEO Company of their SPAs (Single Page Applications) and how well they would do on Google searches (blogs, portfolio websites, product websites, and so on). Sometimes, they also worry about how complex building a server-side rendered application might be. In this tutorial, we’re going to learn how to create server-side rendered applications by using NUXt.js, how to configure your application for development, and how to deploy to Heroku.
Web developers build a lot of Single Page Applications using JavaScript frameworks (Angular, React, Vue). SPAs dynamically populate the contents of their pages on load which means by the time Google crawls their site, the important content is yet to be injected into the site. Part of this problem can be solved by pre-rendering your application’s content. This is where server-side applications come in, and for Vuejs developers, we can build server-side applications using NUXt.js.
We’re going to assume that you have not used it before, as such it will start from the ground-up — introducing you to NUXt.js, its file structure and how routing works. While also touching how you can get it to work with Vuex.
At the end of this tutorial, you should be able to go on to build basic web applications in NUXt.js, and if you have been wondering how to get started with NUXt.js, this will do justice to that.
This article is targeted at those that are fairly familiar with Vue.js and it’s a concept, For those without knowledge of Vue.js, consider starting from the official Vuejs documentation and The Net Ninja’s Vuejs playlist.
What Is Nuxt.js?
According to their official page:
“NUXt is a progressive framework based on Vue.js to create modern web applications. It is based on Vue.js official libraries (vue, vue-router and vuex) and powerful development tools (webpack, Babel and PostCSS). NUXt’s goal is to make web development powerful and performant with great developer experience in mind.”
It allows you to create three types of applications, depending on the purpose it’s intended for:
Static Generated pages (Pre-rendering) Static generated applications do not require API requests to fetch the contents of the pages, i.e. the contents are already included in the HTML file. An example of a static site is a portfolio website or a landing page for a product.
Single Page Application Most JavaScript frameworks (React, Angular, Emberjs, Vue, etc) are single page application whose contents are dynamically populated with faster transitions. Most SPAs make use of the HTML5 history API or the location Hash for routing.
Server Side Rendered Applications (SSR) Server-Side Rendering is a technique used to fetch and display client-side data on the server to send a fully rendered page to the client. This is a good approach to get good SEO Company for your application.
Creating Your First Nuxt.js Application
You can create a NUXt.js application in two ways:
Using the scaffolding tool create-nUXt-app.
From scratch.
In case you just want to see the finished app that we would be building, here’s a link to the GitHub repo.
In this tutorial, we would be focused on using create-nUXt-app so let’s get started. If you have npx installed, open your terminal and run this command:
$ npx create-nUXt-app nUXt-tutorial-app
or
$ yarn create nUXt-app nUXt-tutorial-app
For the purpose of this tutorial, nUXt-tutorial-app is the name of the application but feel free to name yours differently.
This would be followed by a list of options that help in configuring your application with what you might need for development.
Here’s what my configuration looks like:
NUXt conguration options. (Large preview)
For the purpose of this tutorial, we do not need axios, linting and Prettier configurations.
Once that is done, we’ll run the following command in our terminal:
$ cd nUXt-tutorial-app $ npm run dev
Your app should now be running on http://localhost:3000 and this is what you should see:
NUXt scaffolding default landing page. (Large preview)
At this point, your app is ready for development.
Understanding Nuxt Folder Structure
Scaffolding the application as we did creates different files and folders which we can start working with. For someone who hasn’t work with NUXt before, this might throw you off balance. So we’ll be looking at the folders, getting to understand their importance.
Assets This folder is for un-compiled files such as images, font files, SASS, LESS or JavaScript files. Let us add create a styles folder and a main.css file and copy and paste the following in it.
a { text-decoration: none; color: inherit; cursor: pointer; } .header { width: 100%; max-width: 500px; margin-left: auto; margin-right: auto; height: 60px; top: 0; position: sticky; background-color: #fff; display: flex; justify-content: space-between; align-items: center; } .logo { width: 40%; max-width: 200px; height: 40px; } .logo .NUXtLogo { max-width: 30px; margin-left: 10px; max-height: 40px; } .nav { width: 60%; height: 40px; display: flex; justify-content: space-between; padding-right: 10px; max-width: 300px; } .nav__link { width: 80px; display: flex; align-items: center; border-radius: 4px; justify-content: center; height: 100%; border: 1px solid #00c58e; cursor: pointer; } .nav__link:active { background-color: #00c58e; border: 1px solid #00c58e; color: #fff; box-shadow: 5px 3px 5px 2px #3f41468c; } .home { padding-top: 30px; } .home__heading { text-align: center; } .directories { display: flex; box-sizing: border-box; padding: 10px; max-width: 1000px; margin: 0 auto; flex-wrap: wrap; justify-content: center; } @media (min-width: 768px) { .directories { justify-content: space-between; } } .directory__container { width: 100%; max-width: 220px; cursor: pointer; border-radius: 4px; border: 1px solid #00c58e; display: flex; height: 60px; margin: 10px 5px; margin-right: 0; justify-content: center; align-items: center; } .directory__name { text-align: center; } .directory { width: 100%; margin: 50px auto; max-width: 450px; border-radius: 4px; border: 1px solid #00c58e; box-sizing: border-box; padding: 10px 0; } .directory__info { padding-left: 10px; line-height: 22px; padding-right: 10px; }
The styles above will be used across the application for what we’ll be building. As you can see we have styles for the navigation and other aspects which we’ll plug into the application as we progress.
Components This folder is one we’re familiar with from Vue.js, it contains your reusable components.
Now, let’s create our first component and name it navBar.vue, and add the following code to it. We want the navbar of the site to display the logo and link to the Home and About pages which we will create in future. This navbar will be visible across the application. It will also make use of some styles that we have added above.
<template> <header class="header"> <div class="logo"> <nUXt-link to="/"> <Logo /> </nUXt-link> </div> <nav class="nav"> <div class="nav__link"> <nUXt-link to="/">Home</nUXt-link> </div> <div class="nav__link"> <nUXt-link to="/About">About</nUXt-link> </div> </nav> </header> </template> <script> import Logo from "@/components/Logo"; export default { name: "nav-bar", components: { Logo } }; </script> <style> </style>
The template section contains what will be visible to the user. We have a header element which contains our logo and nav links. For us to link to the pages, we make use of nUXt-link which provides navigation between component pages.
In the script section, we import the logo component using Nuxt alias @ and declared it in our component for use by adding it as a component. This makes it possible for us to render it in the template.
Layout Here, we’ll be storing our application layouts. This is particularly useful if your application’s design calls for two or more layouts, e.g. one for authenticated users and another for guests or admins. For the purpose of this tutorial, we’ll be sticking to the default layout.
Let us open our default.vue file and add our navBar component to the layout of our application.
<template> <div> <Nav /> <nUXt /> </div> </template> <script> import Nav from "~/components/navBar.vue"; export default { components: { Nav } }; </script>
In the template section, we’ve added our Nav component inside the layout container to always appear at the top after importing it into the file and declaring it in the script section.
The next thing after our Nav component is <nUXt />, which tells NUXt where to render all its routes.
This Nav component is the one we created above. By adding it here, the Nav component will be used across the application.
Middleware This folder was created to house JavaScript files that are required to run before a page(s) is rendered. If you’ve ever used the Vuejs navigation guard, this folder was created for files like that.
Pages This is another folder that developers with Vuejs background would not be familiar with. It works in such a way that every *.vue file is created as a route in your application so it serves as both views and a router folder at the same time, we’ll talk more about this in the next section.
Plugins This is where you store files that you want to run before mounting the root Vue.js application. It is not a required folder so it can be deleted.
nUXt.config.js This file is used to configure your application, it is usually pre-populated based on the config when creating your app. An ideal nUXt.config.js file should look like this by default:
export default { mode: 'universal', /* ** Headers of the page */ head: { title: process.env.npm_package_name || '', meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }, { hid: 'description', name: 'description', content: process.env.npm_package_description || '' } ], link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } ] }, /* ** Customize the progress-bar color */ loading: { color: '#fff' }, /* ** Global CSS */ css: [ ], /* ** Plugins to load before mounting the App */ plugins: [ ], /* ** NUXt.js dev-modules */ buildModules: [ ], /* ** NUXt.js modules */ modules: [ ], /* ** Build configuration */ build: { /* ** You can extend webpack config here */ extend (config, ctx) { } } }
Each time a change is made to this file, your application will automatically restart to reflect the changes. Let’s go over what the properties used in the file mean.
Mode The type of application; either universal or spa. By selecting universal, you’re telling NUXt that you want your app to be able to run on both the server-side and the client-side.
Head All the default meta tags properties and favicon link found inside the head tag in your app is found here. This is because NUXt.js doesn’t have a default index.html file, unlike Vue.js.
loading All NUXt applications come with a default loader component and the color can be customized here.
css You’re expected to enter the link to all your global CSS files so your application can take it into account when mounting the application. We’re going to add the link to our css file to this and restart our application.
/* ** Global CSS */ css: ["~/assets/styles/main.css"]
plugins This is where you connect all the plugins in your plugins folder to the application. It takes in an object with properties such as src that accepts the file path to the plugin and a mode that configures how your application treats such plugin; either as a server-side plugin or a client-side plugin. For example:
{ src: '~/plugins/universal-plugin.js' }, // for server and client plugins { src: '~/plugins/client-side.js', mode: 'client' }, // for client only plugins { src: '~/plugins/server-side.js', mode: 'server' }, // for server side only plugins
This is important to avoid error either on the server-side or client-side especially if your plugin requires something like localStorage that is not available on the server-side.
For more info about the nUXt.config.js file, check out the official doc.
Nuxt Pages And Routing System
The pages folder in your NUXt application is used to configure your application’s routes, i.e. your route name is dependent on the name of each file in this folder, e.g. if you have an about.vue file inside your pages file, it means you now have an /about route in your app, but that’s not all. What happens if you want a dynamic route for your application? Or a nested route? How do you go about it? let’s find out.
Basic Routes
Basic routes can be classified as routes that do not require extra configuration for them to work. For example, a direct route /work or a /contact route. So if your pages folder looks like this:
pages/ --| me/ -----| index.vue -----| about.vue --| work.vue --| contact.vue --| index.vue
NUXt would automatically generate a router config that looks like this:
router: { routes: [ { name: 'index', path: '/', component: 'pages/index.vue' }, { name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' } ] }
These paths can then be used to access the components tied to them. You can see that the path does not contain pages. And NUXt handles the components named index.vue as it should without an additional config for that.
Nested Routes
To create a nested route, create a folder called dashboard inside the pages folder. This folder should contain all the files you want to nest in it. For example, user.vue and settings.vue. Then at the root of pages folder, create a file called dashboard.vue.
pages/ --| me/ -----| index.vue -----| about.vue --| dashboard/ -----| user.vue -----| settings.vue --| dashboard.vue --| work.vue --| contact.vue --| index.vue
This would automatically generate a router with routes that look like this:
router: { routes: [ { name: 'index', path: '/', component: 'pages/index.vue' }, { name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' }, { name: 'dashboard', path: '/dashboard', component: 'pages/dashboard.vue', children: [ { name: 'dashboard-user', path: '/dashboard/user', component: 'pages/dashboard/user.vue' }, { name: 'dashboard-settings', path: '/dashboard/settings', component: 'pages/dashboard/settings.vue' } ] } ] }
Notice that the route name always follows a regular pattern:
name of the folder + '-' + name of the file
With this, you can be sure that each route will have a unique name.
Dynamic Routes
Dynamic routes are routes that are defined by a variable, this variable can either be a name, number or an id gotten from client data on the app. This comes in handy when working with an API, where the id will likely be the id of the item coming from the database.
In NUXt, dynamic routes are defined by appending an _ to a file name or folder name in the pages folder. For instance, if you want a dynamic route whose variable name is id, all you need is to name your file _id.vue and NUXt automatically creates a dynamic route for you. For example:
pages/ --| me/ -----| index.vue -----| about.vue -----| _routeName -------| index.vue -------| info.vue --| dashboard/ -----| user.vue -----| settings.vue --| dashboard.vue --| work.vue --| _id.vue --| contact.vue --| index.vue
This would automatically create a router file with the following routes,
{ name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'id', path: '/:id', component: 'pages/_id.vue' } { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' }, { name: 'me-routeName', path: '/me/:routeName', component: 'pages/me/_routeName/index.vue' }, { name: 'me-routeName-info', path: '/me/:routeName/info', component: 'pages/me/route.vue' }, { name: 'dashboard', path: '/dashboard', component: 'pages/dashboard.vue', children: [ { name: 'dashboard-user', path: '/dashboard/user', component: 'pages/dashboard/user.vue' }, { name: 'dashboard-settings', path: '/dashboard/settings', component: 'pages/dashboard/settings.vue' } ] } ] }
Although some of the Vue.js router tags work in NUXt and can be used interchangeably, it is recommended that we use NUXt router components. Here are some of the differences between the NUXt Router tags and Vue.js Router tags.
VueJsNUXtJSrouter-linknUXt-linkrouter-view (for nested routes)nUXt-childrouter-view(default)nUXt
Difference between vue.js router and nUXt.js router
At this point, Here’s what your app should look like this, with the navigation shown at the top.
The Landing page. (Large preview)
Now that we understand how NUXt pages and Routes work, let’s add our first page and route about.vue. This page would list some directories in the application with a link to a new page that shows more information about such directory.
Let us add the following code to it:
<template> <section class="home"> <h1 class="home__heading">About NUXtjs Directory Structure</h1> <div class="directories"> <div class="directory__container" v-for="directory in directories" :key="directory.id"> <p class="directory__name"> <nUXt-link :to="{ name: 'id', params: { id: directory.id, dir: directory } }" ></nUXt-link> </p> </div> </div> </section> </template> <script> export default { name: "about-nUXt", data() { return { directories: [ { id: 0, name: "The Assets Directory", info: "By default, NUXt uses vue-loader, file-loader and url-loader webpack loaders for strong assets serving. You can also use the static directory for static assets. This folder is for un-compiled files such as images, font files, SASS, LESS or JavaScript files" }, { id: 1, name: "The Components Directory", info: "The components directory contains your Vue.js Components. You can’t use asyncData in these components." }, { id: 2, name: "The Layouts Directory", info: "The layouts directory includes your application layouts. Layouts are used to change the look and feel of your page (for example by including a sidebar). Layouts are a great help when you want to change the look and feel of your NUXt.js app. Whether you want to include a sidebar or having distinct layouts for mobile and desktop" }, { id: 3, name: "The Middleware Directory", info: "The middleware directory contains your Application Middleware. Middleware lets you define custom functions that can be run before rendering either a page or a group of pages (layouts)." }, { id: 4, name: "The Pages Directory", info: "The pages directory contains your Application Views and Routes. The framework reads all the .vue files inside this directory and creates the application router. Every Page component is a Vue component but NUXt.js adds special attributes and functions to make the development of your universal application as easy as possible" }, { id: 5, name: "The Plugins Directory", info: "The plugins directory contains your Javascript plugins that you want to run before instantiating the root Vue.js Application. This is the place to register components globally and to inject functions or constants. NUXt.js allows you to define JavaScript plugins to be run before instantiating the root Vue.js Application. This is especially helpful when using your own libraries or external modules." }, { id: 6, name: "The Static Directory", info: "The static directory is directly mapped to the server root (/static/robots.txt is accessible under http://localhost:3000/robots.txt) and contains files that likely won’t be changed (e.g. the favicon). If you don’t want to use Webpack assets from the assets directory, you can create and use the static directory (in your project root folder)." }, { id: 7, name: "The Store Directory", info: "The store directory contains your Vuex Store files. The Vuex Store comes with NUXt.js out of the box but is disabled by default. Creating an index.js file in this directory enables the store. Using a store to manage the state is important for every big application. That’s why NUXt.js implements Vuex in its core." } ] }; } }; </script> <style> </style>
Starting from the script section, we created an array which we store in the directories variable. Each array contains an object with id, name, and info. This is the data we’ll show to the user when this page is opened. We want to show it to the user such that the names are clickable.
We do that in the template section, using v-for to loop through the array. This makes it possible to get each item in the array, which we can access using directory. In the loop, we use nUXt-link to handle the linking of each time. Using nUXt-link, we pass the details (id, name and info) of each directory item via nUXt router. We do this because we want to be able to display this on the show page when the user clicks on an item.
If you navigate to the /about route using your browser, you should see something like this:
About page. (Large preview)
Now, let’s create a new file and name it _id.vue. This would automatically create a dynamic route that takes the id param from the link display a little information about any directory clicked on from the About page.
Let us add this to our file:
<template> <section class="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section> </template> <script> export default { name: "directory-info", data() { return { directory: this.$route.params.dir }; } }; </script> <style> </style>
What we have done is to create a page that fetches data from the route param dir using the this.$route.params. This gets us the name and info of the clicked directory, which we then display to the user.
So if you click on any directory link (e.g. store directory), you should see this.
What the ID page looks like. (Large preview)
But there’s a problem, if you refresh this page, your directory info gets lost and you get an error. This would be fixed using our Vuex Store so let’s dive into it.
Using Vuex Store In Nuxt
Vuex can be accessed in NUXt using two modes:
Classic mode (deprecated).
Modules mode.
Modules mode
NUXt automatically creates a Store folder upon the creation of your app. In Modules mode, NUXt would treat every file inside this folder as a module but index.js is required for Vuex store to be activated in your app. So let’s create an index.js file in our store folder and set it up for use. Let us add the following to our file.
index.js
export const state = () => ({ }) export const getters = { } export const mutations = { } export const actions = { }
All we have done is to set up the store for our file with all we might need; the state for storing data, getters for performing extra manipulation to our state, mutations for modifying our state and actions for committing mutations.
NUXt also allows users to separate each core concept into different files which means we can have store.js, getters.js, mutation.js and action.js and this is good as it makes for easy maintainability. Now, we fix the problem of directory disappearing on refresh, we’ll use the store, but first, we need to install and set up Vuex persist for our store.
Install Vuex persist from npm using either command below, depending on your preference.
$ npm install --save vuex-persist
or
$ yarn add vuex-persist
After installing, we’re going to create a vuex-persist.js file in our plugins folder and add the following:
import VuexPersistence from 'vuex-persist' export default ({ store }) => { window.onNUXtReady(() => { new VuexPersistence({ storage: window.localStorage }).plugin(store); }); }
Here, we import our plugin from node-modules and configure it to save your store in localStorage. This plugin allows you to choose other storage options such as sessionStorage too so feel free to explore their documentation for more info.
Remember to add it to your nUXt.config.js file.
/* ** Plugins to load before mounting the App */ plugins: [{ src: '~/plugins/vuex-persist', mode: 'client' }],
Here, we added the file path to our plugin and told NUXt to only run this plugin on the client side of this application.
Now, we can set our store up to accept and store directory info. Update your store to handle directory info like this:
export const state = () => ({ directory: '' }) export const getters = { } export const mutations = { saveInfo(state, payload) { state.directory = payload.directory } } export const actions = { }
What we’ve done is to add a directory state to our store and a mutation function saveInfo that modifies the value of the directory state we added to our store in anticipation of the data we’d be passing it soon.
Next, in your about.vue file, update it to look like this.
<template> <section class="home"> <h1 class="home__heading">About NUXtjs Directory Structure</h1> <div class="directories"> <div class="directory__container" v-for="directory in directories" :key="directory.id" @click.prevent="storeDirectoryInfo(directory)" > <p class="directory__name"> <nUXt-link :to="{ name: 'id', params: { id: directory.id, dir: directory } }" ></nUXt-link> </p> </div> </div> </section> </template> <script> export default { name: "about-nUXt", data() { return { directories: [ //remains the same ] }; }, methods: { storeDirectoryInfo(dir) { this.$store.commit("saveInfo", { directory: dir }); } } }; </script> <style> </style>
Now, we’ve added a click event to every directory container that passes the directory info as an argument to the storeDirectoryInfo. In this function, we commit the directory object to our store.
Finally, we would go back to our _id.vue file and replace the directory variable with our data from the store like this:
<template> <section class="directory" v-if="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section> </template> <script> import { mapState } from "vuex"; export default { name: "directory-info", computed: { ...mapState(["directory"]) } }; </script> <style></style>
Here, we refactor our code to use directory object directly from our store by first importing mapState from Vuex.
import { mapState } from 'vuex';
Instead of first checking if this.$route.params.dir is undefined before accessing the data from our store, we decide to use our store by reading the data that’s in the store.
<script> import { mapState } from "vuex"; export default { name: "directory-info", computed: { ...mapState(["directory"]) } }; </script>
Then we update our template to make sure it doesn’t render while directory is undefined.
<template> <section class="directory" v-if="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section> </template>
On doing this, no matter how many times we refresh our app, our directory object is safe in our store and can be easily accessed using the …mapState(['stateVariable']) method.
Deploying To Heroku
Now that our nUXt-tutorial-app app is complete, what’s next? Deploying our shiny new app to production.
We’ll be deploying our NUXt.js app to Heroku using Github for easy deployment so if you’ve not set up a repository for your app, now would be a time to do so. The next thing would be to open Heroku and create a new app, choose a name and connect it to GitHub and the repo created above. Next, go to your settings, you should see something like this.
Heroku App settings page. (Large preview)
Now, add the following config variables.
NPM_CONFIG_PRODUCTION=false HOST=0.0.0.0 NODE_ENV=production
The next thing we have to do is to create a Procfile in the root folder of our app (same level as nUXt.config.js) and enter this command:
web: nUXt start
This will run the nUXt start command and tell Heroku to direct external HTTP traffic to it.
After adding the Procfile to your app, commit and push your changes to your repo. If you have automatic deploys enabled for your app, your app should be live and accessible from its URL. If you can see your app live, congratulations! you have successfully built and deployed your first NUXt.js application.
Conclusion
Now that we know how to create a basic NUXt application and deploy to Heroku, what’s next? Here are some resources that cover things like using Axios in NUXt and implementing authentication in your app.
Using the axios module.
Implementing Authentication in Nuxt.
NUXt.js official documentation.
nUXt-tutorial-app Github repo.
(ks, ra, yk, il)
Website Design & SEO Delray Beach by DBL07.co
Delray Beach SEO
source http://www.scpie.org/getting-started-with-nuxt/ source https://scpie1.blogspot.com/2020/04/getting-started-with-nuxt.html
0 notes
Text
Getting Started With Nuxt
About The Author
Front-end developer based in Lagos, Nigeria. He enjoys converting designs into code and building things for the web. More about Timi …
Developers often worry about the SEO Company of their SPAs (Single Page Applications) and how well they would do on Google searches (blogs, portfolio websites, product websites, and so on). Sometimes, they also worry about how complex building a server-side rendered application might be. In this tutorial, we’re going to learn how to create server-side rendered applications by using NUXt.js, how to configure your application for development, and how to deploy to Heroku.
Web developers build a lot of Single Page Applications using JavaScript frameworks (Angular, React, Vue). SPAs dynamically populate the contents of their pages on load which means by the time Google crawls their site, the important content is yet to be injected into the site. Part of this problem can be solved by pre-rendering your application’s content. This is where server-side applications come in, and for Vuejs developers, we can build server-side applications using NUXt.js.
We’re going to assume that you have not used it before, as such it will start from the ground-up — introducing you to NUXt.js, its file structure and how routing works. While also touching how you can get it to work with Vuex.
At the end of this tutorial, you should be able to go on to build basic web applications in NUXt.js, and if you have been wondering how to get started with NUXt.js, this will do justice to that.
This article is targeted at those that are fairly familiar with Vue.js and it’s a concept, For those without knowledge of Vue.js, consider starting from the official Vuejs documentation and The Net Ninja’s Vuejs playlist.
What Is Nuxt.js?
According to their official page:
“NUXt is a progressive framework based on Vue.js to create modern web applications. It is based on Vue.js official libraries (vue, vue-router and vuex) and powerful development tools (webpack, Babel and PostCSS). NUXt’s goal is to make web development powerful and performant with great developer experience in mind.”
It allows you to create three types of applications, depending on the purpose it’s intended for:
Static Generated pages (Pre-rendering) Static generated applications do not require API requests to fetch the contents of the pages, i.e. the contents are already included in the HTML file. An example of a static site is a portfolio website or a landing page for a product.
Single Page Application Most JavaScript frameworks (React, Angular, Emberjs, Vue, etc) are single page application whose contents are dynamically populated with faster transitions. Most SPAs make use of the HTML5 history API or the location Hash for routing.
Server Side Rendered Applications (SSR) Server-Side Rendering is a technique used to fetch and display client-side data on the server to send a fully rendered page to the client. This is a good approach to get good SEO Company for your application.
Creating Your First Nuxt.js Application
You can create a NUXt.js application in two ways:
Using the scaffolding tool create-nUXt-app.
From scratch.
In case you just want to see the finished app that we would be building, here’s a link to the GitHub repo.
In this tutorial, we would be focused on using create-nUXt-app so let’s get started. If you have npx installed, open your terminal and run this command:
$ npx create-nUXt-app nUXt-tutorial-app
or
$ yarn create nUXt-app nUXt-tutorial-app
For the purpose of this tutorial, nUXt-tutorial-app is the name of the application but feel free to name yours differently.
This would be followed by a list of options that help in configuring your application with what you might need for development.
Here’s what my configuration looks like:
NUXt conguration options. (Large preview)
For the purpose of this tutorial, we do not need axios, linting and Prettier configurations.
Once that is done, we’ll run the following command in our terminal:
$ cd nUXt-tutorial-app $ npm run dev
Your app should now be running on http://localhost:3000 and this is what you should see:
NUXt scaffolding default landing page. (Large preview)
At this point, your app is ready for development.
Understanding Nuxt Folder Structure
Scaffolding the application as we did creates different files and folders which we can start working with. For someone who hasn’t work with NUXt before, this might throw you off balance. So we’ll be looking at the folders, getting to understand their importance.
Assets This folder is for un-compiled files such as images, font files, SASS, LESS or JavaScript files. Let us add create a styles folder and a main.css file and copy and paste the following in it.
a { text-decoration: none; color: inherit; cursor: pointer; } .header { width: 100%; max-width: 500px; margin-left: auto; margin-right: auto; height: 60px; top: 0; position: sticky; background-color: #fff; display: flex; justify-content: space-between; align-items: center; } .logo { width: 40%; max-width: 200px; height: 40px; } .logo .NUXtLogo { max-width: 30px; margin-left: 10px; max-height: 40px; } .nav { width: 60%; height: 40px; display: flex; justify-content: space-between; padding-right: 10px; max-width: 300px; } .nav__link { width: 80px; display: flex; align-items: center; border-radius: 4px; justify-content: center; height: 100%; border: 1px solid #00c58e; cursor: pointer; } .nav__link:active { background-color: #00c58e; border: 1px solid #00c58e; color: #fff; box-shadow: 5px 3px 5px 2px #3f41468c; } .home { padding-top: 30px; } .home__heading { text-align: center; } .directories { display: flex; box-sizing: border-box; padding: 10px; max-width: 1000px; margin: 0 auto; flex-wrap: wrap; justify-content: center; } @media (min-width: 768px) { .directories { justify-content: space-between; } } .directory__container { width: 100%; max-width: 220px; cursor: pointer; border-radius: 4px; border: 1px solid #00c58e; display: flex; height: 60px; margin: 10px 5px; margin-right: 0; justify-content: center; align-items: center; } .directory__name { text-align: center; } .directory { width: 100%; margin: 50px auto; max-width: 450px; border-radius: 4px; border: 1px solid #00c58e; box-sizing: border-box; padding: 10px 0; } .directory__info { padding-left: 10px; line-height: 22px; padding-right: 10px; }
The styles above will be used across the application for what we’ll be building. As you can see we have styles for the navigation and other aspects which we’ll plug into the application as we progress.
Components This folder is one we’re familiar with from Vue.js, it contains your reusable components.
Now, let’s create our first component and name it navBar.vue, and add the following code to it. We want the navbar of the site to display the logo and link to the Home and About pages which we will create in future. This navbar will be visible across the application. It will also make use of some styles that we have added above.
<template> <header class="header"> <div class="logo"> <nUXt-link to="/"> <Logo /> </nUXt-link> </div> <nav class="nav"> <div class="nav__link"> <nUXt-link to="/">Home</nUXt-link> </div> <div class="nav__link"> <nUXt-link to="/About">About</nUXt-link> </div> </nav> </header> </template> <script> import Logo from "@/components/Logo"; export default { name: "nav-bar", components: { Logo } }; </script> <style> </style>
The template section contains what will be visible to the user. We have a header element which contains our logo and nav links. For us to link to the pages, we make use of nUXt-link which provides navigation between component pages.
In the script section, we import the logo component using Nuxt alias @ and declared it in our component for use by adding it as a component. This makes it possible for us to render it in the template.
Layout Here, we’ll be storing our application layouts. This is particularly useful if your application’s design calls for two or more layouts, e.g. one for authenticated users and another for guests or admins. For the purpose of this tutorial, we’ll be sticking to the default layout.
Let us open our default.vue file and add our navBar component to the layout of our application.
<template> <div> <Nav /> <nUXt /> </div> </template> <script> import Nav from "~/components/navBar.vue"; export default { components: { Nav } }; </script>
In the template section, we’ve added our Nav component inside the layout container to always appear at the top after importing it into the file and declaring it in the script section.
The next thing after our Nav component is <nUXt />, which tells NUXt where to render all its routes.
This Nav component is the one we created above. By adding it here, the Nav component will be used across the application.
Middleware This folder was created to house JavaScript files that are required to run before a page(s) is rendered. If you’ve ever used the Vuejs navigation guard, this folder was created for files like that.
Pages This is another folder that developers with Vuejs background would not be familiar with. It works in such a way that every *.vue file is created as a route in your application so it serves as both views and a router folder at the same time, we’ll talk more about this in the next section.
Plugins This is where you store files that you want to run before mounting the root Vue.js application. It is not a required folder so it can be deleted.
nUXt.config.js This file is used to configure your application, it is usually pre-populated based on the config when creating your app. An ideal nUXt.config.js file should look like this by default:
export default { mode: 'universal', /* ** Headers of the page */ head: { title: process.env.npm_package_name || '', meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }, { hid: 'description', name: 'description', content: process.env.npm_package_description || '' } ], link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } ] }, /* ** Customize the progress-bar color */ loading: { color: '#fff' }, /* ** Global CSS */ css: [ ], /* ** Plugins to load before mounting the App */ plugins: [ ], /* ** NUXt.js dev-modules */ buildModules: [ ], /* ** NUXt.js modules */ modules: [ ], /* ** Build configuration */ build: { /* ** You can extend webpack config here */ extend (config, ctx) { } } }
Each time a change is made to this file, your application will automatically restart to reflect the changes. Let’s go over what the properties used in the file mean.
Mode The type of application; either universal or spa. By selecting universal, you’re telling NUXt that you want your app to be able to run on both the server-side and the client-side.
Head All the default meta tags properties and favicon link found inside the head tag in your app is found here. This is because NUXt.js doesn’t have a default index.html file, unlike Vue.js.
loading All NUXt applications come with a default loader component and the color can be customized here.
css You’re expected to enter the link to all your global CSS files so your application can take it into account when mounting the application. We’re going to add the link to our css file to this and restart our application.
/* ** Global CSS */ css: ["~/assets/styles/main.css"]
plugins This is where you connect all the plugins in your plugins folder to the application. It takes in an object with properties such as src that accepts the file path to the plugin and a mode that configures how your application treats such plugin; either as a server-side plugin or a client-side plugin. For example:
{ src: '~/plugins/universal-plugin.js' }, // for server and client plugins { src: '~/plugins/client-side.js', mode: 'client' }, // for client only plugins { src: '~/plugins/server-side.js', mode: 'server' }, // for server side only plugins
This is important to avoid error either on the server-side or client-side especially if your plugin requires something like localStorage that is not available on the server-side.
For more info about the nUXt.config.js file, check out the official doc.
Nuxt Pages And Routing System
The pages folder in your NUXt application is used to configure your application’s routes, i.e. your route name is dependent on the name of each file in this folder, e.g. if you have an about.vue file inside your pages file, it means you now have an /about route in your app, but that’s not all. What happens if you want a dynamic route for your application? Or a nested route? How do you go about it? let’s find out.
Basic Routes
Basic routes can be classified as routes that do not require extra configuration for them to work. For example, a direct route /work or a /contact route. So if your pages folder looks like this:
pages/ --| me/ -----| index.vue -----| about.vue --| work.vue --| contact.vue --| index.vue
NUXt would automatically generate a router config that looks like this:
router: { routes: [ { name: 'index', path: '/', component: 'pages/index.vue' }, { name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' } ] }
These paths can then be used to access the components tied to them. You can see that the path does not contain pages. And NUXt handles the components named index.vue as it should without an additional config for that.
Nested Routes
To create a nested route, create a folder called dashboard inside the pages folder. This folder should contain all the files you want to nest in it. For example, user.vue and settings.vue. Then at the root of pages folder, create a file called dashboard.vue.
pages/ --| me/ -----| index.vue -----| about.vue --| dashboard/ -----| user.vue -----| settings.vue --| dashboard.vue --| work.vue --| contact.vue --| index.vue
This would automatically generate a router with routes that look like this:
router: { routes: [ { name: 'index', path: '/', component: 'pages/index.vue' }, { name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' }, { name: 'dashboard', path: '/dashboard', component: 'pages/dashboard.vue', children: [ { name: 'dashboard-user', path: '/dashboard/user', component: 'pages/dashboard/user.vue' }, { name: 'dashboard-settings', path: '/dashboard/settings', component: 'pages/dashboard/settings.vue' } ] } ] }
Notice that the route name always follows a regular pattern:
name of the folder + '-' + name of the file
With this, you can be sure that each route will have a unique name.
Dynamic Routes
Dynamic routes are routes that are defined by a variable, this variable can either be a name, number or an id gotten from client data on the app. This comes in handy when working with an API, where the id will likely be the id of the item coming from the database.
In NUXt, dynamic routes are defined by appending an _ to a file name or folder name in the pages folder. For instance, if you want a dynamic route whose variable name is id, all you need is to name your file _id.vue and NUXt automatically creates a dynamic route for you. For example:
pages/ --| me/ -----| index.vue -----| about.vue -----| _routeName -------| index.vue -------| info.vue --| dashboard/ -----| user.vue -----| settings.vue --| dashboard.vue --| work.vue --| _id.vue --| contact.vue --| index.vue
This would automatically create a router file with the following routes,
{ name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'id', path: '/:id', component: 'pages/_id.vue' } { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' }, { name: 'me-routeName', path: '/me/:routeName', component: 'pages/me/_routeName/index.vue' }, { name: 'me-routeName-info', path: '/me/:routeName/info', component: 'pages/me/route.vue' }, { name: 'dashboard', path: '/dashboard', component: 'pages/dashboard.vue', children: [ { name: 'dashboard-user', path: '/dashboard/user', component: 'pages/dashboard/user.vue' }, { name: 'dashboard-settings', path: '/dashboard/settings', component: 'pages/dashboard/settings.vue' } ] } ] }
Although some of the Vue.js router tags work in NUXt and can be used interchangeably, it is recommended that we use NUXt router components. Here are some of the differences between the NUXt Router tags and Vue.js Router tags.
VueJs NUXtJS router-link nUXt-link router-view (for nested routes) nUXt-child router-view(default) nUXt
Difference between vue.js router and nUXt.js router
At this point, Here’s what your app should look like this, with the navigation shown at the top.
The Landing page. (Large preview)
Now that we understand how NUXt pages and Routes work, let’s add our first page and route about.vue. This page would list some directories in the application with a link to a new page that shows more information about such directory.
Let us add the following code to it:
<template> <section class="home"> <h1 class="home__heading">About NUXtjs Directory Structure</h1> <div class="directories"> <div class="directory__container" v-for="directory in directories" :key="directory.id"> <p class="directory__name"> <nUXt-link :to="{ name: 'id', params: { id: directory.id, dir: directory } }" ></nUXt-link> </p> </div> </div> </section> </template> <script> export default { name: "about-nUXt", data() { return { directories: [ { id: 0, name: "The Assets Directory", info: "By default, NUXt uses vue-loader, file-loader and url-loader webpack loaders for strong assets serving. You can also use the static directory for static assets. This folder is for un-compiled files such as images, font files, SASS, LESS or JavaScript files" }, { id: 1, name: "The Components Directory", info: "The components directory contains your Vue.js Components. You can’t use asyncData in these components." }, { id: 2, name: "The Layouts Directory", info: "The layouts directory includes your application layouts. Layouts are used to change the look and feel of your page (for example by including a sidebar). Layouts are a great help when you want to change the look and feel of your NUXt.js app. Whether you want to include a sidebar or having distinct layouts for mobile and desktop" }, { id: 3, name: "The Middleware Directory", info: "The middleware directory contains your Application Middleware. Middleware lets you define custom functions that can be run before rendering either a page or a group of pages (layouts)." }, { id: 4, name: "The Pages Directory", info: "The pages directory contains your Application Views and Routes. The framework reads all the .vue files inside this directory and creates the application router. Every Page component is a Vue component but NUXt.js adds special attributes and functions to make the development of your universal application as easy as possible" }, { id: 5, name: "The Plugins Directory", info: "The plugins directory contains your Javascript plugins that you want to run before instantiating the root Vue.js Application. This is the place to register components globally and to inject functions or constants. NUXt.js allows you to define JavaScript plugins to be run before instantiating the root Vue.js Application. This is especially helpful when using your own libraries or external modules." }, { id: 6, name: "The Static Directory", info: "The static directory is directly mapped to the server root (/static/robots.txt is accessible under http://localhost:3000/robots.txt) and contains files that likely won’t be changed (e.g. the favicon). If you don’t want to use Webpack assets from the assets directory, you can create and use the static directory (in your project root folder)." }, { id: 7, name: "The Store Directory", info: "The store directory contains your Vuex Store files. The Vuex Store comes with NUXt.js out of the box but is disabled by default. Creating an index.js file in this directory enables the store. Using a store to manage the state is important for every big application. That’s why NUXt.js implements Vuex in its core." } ] }; } }; </script> <style> </style>
Starting from the script section, we created an array which we store in the directories variable. Each array contains an object with id, name, and info. This is the data we’ll show to the user when this page is opened. We want to show it to the user such that the names are clickable.
We do that in the template section, using v-for to loop through the array. This makes it possible to get each item in the array, which we can access using directory. In the loop, we use nUXt-link to handle the linking of each time. Using nUXt-link, we pass the details (id, name and info) of each directory item via nUXt router. We do this because we want to be able to display this on the show page when the user clicks on an item.
If you navigate to the /about route using your browser, you should see something like this:
About page. (Large preview)
Now, let’s create a new file and name it _id.vue. This would automatically create a dynamic route that takes the id param from the link display a little information about any directory clicked on from the About page.
Let us add this to our file:
<template> <section class="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section> </template> <script> export default { name: "directory-info", data() { return { directory: this.$route.params.dir }; } }; </script> <style> </style>
What we have done is to create a page that fetches data from the route param dir using the this.$route.params. This gets us the name and info of the clicked directory, which we then display to the user.
So if you click on any directory link (e.g. store directory), you should see this.
What the ID page looks like. (Large preview)
But there’s a problem, if you refresh this page, your directory info gets lost and you get an error. This would be fixed using our Vuex Store so let’s dive into it.
Using Vuex Store In Nuxt
Vuex can be accessed in NUXt using two modes:
Classic mode (deprecated).
Modules mode.
Modules mode
NUXt automatically creates a Store folder upon the creation of your app. In Modules mode, NUXt would treat every file inside this folder as a module but index.js is required for Vuex store to be activated in your app. So let’s create an index.js file in our store folder and set it up for use. Let us add the following to our file.
index.js
export const state = () => ({ }) export const getters = { } export const mutations = { } export const actions = { }
All we have done is to set up the store for our file with all we might need; the state for storing data, getters for performing extra manipulation to our state, mutations for modifying our state and actions for committing mutations.
NUXt also allows users to separate each core concept into different files which means we can have store.js, getters.js, mutation.js and action.js and this is good as it makes for easy maintainability. Now, we fix the problem of directory disappearing on refresh, we’ll use the store, but first, we need to install and set up Vuex persist for our store.
Install Vuex persist from npm using either command below, depending on your preference.
$ npm install --save vuex-persist
or
$ yarn add vuex-persist
After installing, we’re going to create a vuex-persist.js file in our plugins folder and add the following:
import VuexPersistence from 'vuex-persist' export default ({ store }) => { window.onNUXtReady(() => { new VuexPersistence({ storage: window.localStorage }).plugin(store); }); }
Here, we import our plugin from node-modules and configure it to save your store in localStorage. This plugin allows you to choose other storage options such as sessionStorage too so feel free to explore their documentation for more info.
Remember to add it to your nUXt.config.js file.
/* ** Plugins to load before mounting the App */ plugins: [{ src: '~/plugins/vuex-persist', mode: 'client' }],
Here, we added the file path to our plugin and told NUXt to only run this plugin on the client side of this application.
Now, we can set our store up to accept and store directory info. Update your store to handle directory info like this:
export const state = () => ({ directory: '' }) export const getters = { } export const mutations = { saveInfo(state, payload) { state.directory = payload.directory } } export const actions = { }
What we’ve done is to add a directory state to our store and a mutation function saveInfo that modifies the value of the directory state we added to our store in anticipation of the data we’d be passing it soon.
Next, in your about.vue file, update it to look like this.
<template> <section class="home"> <h1 class="home__heading">About NUXtjs Directory Structure</h1> <div class="directories"> <div class="directory__container" v-for="directory in directories" :key="directory.id" @click.prevent="storeDirectoryInfo(directory)" > <p class="directory__name"> <nUXt-link :to="{ name: 'id', params: { id: directory.id, dir: directory } }" ></nUXt-link> </p> </div> </div> </section> </template> <script> export default { name: "about-nUXt", data() { return { directories: [ //remains the same ] }; }, methods: { storeDirectoryInfo(dir) { this.$store.commit("saveInfo", { directory: dir }); } } }; </script> <style> </style>
Now, we’ve added a click event to every directory container that passes the directory info as an argument to the storeDirectoryInfo. In this function, we commit the directory object to our store.
Finally, we would go back to our _id.vue file and replace the directory variable with our data from the store like this:
<template> <section class="directory" v-if="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section> </template> <script> import { mapState } from "vuex"; export default { name: "directory-info", computed: { ...mapState(["directory"]) } }; </script> <style></style>
Here, we refactor our code to use directory object directly from our store by first importing mapState from Vuex.
import { mapState } from 'vuex';
Instead of first checking if this.$route.params.dir is undefined before accessing the data from our store, we decide to use our store by reading the data that’s in the store.
<script> import { mapState } from "vuex"; export default { name: "directory-info", computed: { ...mapState(["directory"]) } }; </script>
Then we update our template to make sure it doesn’t render while directory is undefined.
<template> <section class="directory" v-if="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section> </template>
On doing this, no matter how many times we refresh our app, our directory object is safe in our store and can be easily accessed using the …mapState(['stateVariable']) method.
Deploying To Heroku
Now that our nUXt-tutorial-app app is complete, what’s next? Deploying our shiny new app to production.
We’ll be deploying our NUXt.js app to Heroku using Github for easy deployment so if you’ve not set up a repository for your app, now would be a time to do so. The next thing would be to open Heroku and create a new app, choose a name and connect it to GitHub and the repo created above. Next, go to your settings, you should see something like this.
Heroku App settings page. (Large preview)
Now, add the following config variables.
NPM_CONFIG_PRODUCTION=false HOST=0.0.0.0 NODE_ENV=production
The next thing we have to do is to create a Procfile in the root folder of our app (same level as nUXt.config.js) and enter this command:
web: nUXt start
This will run the nUXt start command and tell Heroku to direct external HTTP traffic to it.
After adding the Procfile to your app, commit and push your changes to your repo. If you have automatic deploys enabled for your app, your app should be live and accessible from its URL. If you can see your app live, congratulations! you have successfully built and deployed your first NUXt.js application.
Conclusion
Now that we know how to create a basic NUXt application and deploy to Heroku, what’s next? Here are some resources that cover things like using Axios in NUXt and implementing authentication in your app.
Using the axios module.
Implementing Authentication in Nuxt.
NUXt.js official documentation.
nUXt-tutorial-app Github repo.
(ks, ra, yk, il)
Website Design & SEO Delray Beach by DBL07.co
Delray Beach SEO
source http://www.scpie.org/getting-started-with-nuxt/ source https://scpie.tumblr.com/post/616566323517980672
0 notes
Text
Getting Started With Nuxt
About The Author
Front-end developer based in Lagos, Nigeria. He enjoys converting designs into code and building things for the web. More about Timi …
Developers often worry about the SEO Company of their SPAs (Single Page Applications) and how well they would do on Google searches (blogs, portfolio websites, product websites, and so on). Sometimes, they also worry about how complex building a server-side rendered application might be. In this tutorial, we’re going to learn how to create server-side rendered applications by using NUXt.js, how to configure your application for development, and how to deploy to Heroku.
Web developers build a lot of Single Page Applications using JavaScript frameworks (Angular, React, Vue). SPAs dynamically populate the contents of their pages on load which means by the time Google crawls their site, the important content is yet to be injected into the site. Part of this problem can be solved by pre-rendering your application’s content. This is where server-side applications come in, and for Vuejs developers, we can build server-side applications using NUXt.js.
We’re going to assume that you have not used it before, as such it will start from the ground-up — introducing you to NUXt.js, its file structure and how routing works. While also touching how you can get it to work with Vuex.
At the end of this tutorial, you should be able to go on to build basic web applications in NUXt.js, and if you have been wondering how to get started with NUXt.js, this will do justice to that.
This article is targeted at those that are fairly familiar with Vue.js and it’s a concept, For those without knowledge of Vue.js, consider starting from the official Vuejs documentation and The Net Ninja’s Vuejs playlist.
What Is Nuxt.js?
According to their official page:
“NUXt is a progressive framework based on Vue.js to create modern web applications. It is based on Vue.js official libraries (vue, vue-router and vuex) and powerful development tools (webpack, Babel and PostCSS). NUXt’s goal is to make web development powerful and performant with great developer experience in mind.”
It allows you to create three types of applications, depending on the purpose it’s intended for:
Static Generated pages (Pre-rendering) Static generated applications do not require API requests to fetch the contents of the pages, i.e. the contents are already included in the HTML file. An example of a static site is a portfolio website or a landing page for a product.
Single Page Application Most JavaScript frameworks (React, Angular, Emberjs, Vue, etc) are single page application whose contents are dynamically populated with faster transitions. Most SPAs make use of the HTML5 history API or the location Hash for routing.
Server Side Rendered Applications (SSR) Server-Side Rendering is a technique used to fetch and display client-side data on the server to send a fully rendered page to the client. This is a good approach to get good SEO Company for your application.
Creating Your First Nuxt.js Application
You can create a NUXt.js application in two ways:
Using the scaffolding tool create-nUXt-app.
From scratch.
In case you just want to see the finished app that we would be building, here’s a link to the GitHub repo.
In this tutorial, we would be focused on using create-nUXt-app so let’s get started. If you have npx installed, open your terminal and run this command:
$ npx create-nUXt-app nUXt-tutorial-app
or
$ yarn create nUXt-app nUXt-tutorial-app
For the purpose of this tutorial, nUXt-tutorial-app is the name of the application but feel free to name yours differently.
This would be followed by a list of options that help in configuring your application with what you might need for development.
Here’s what my configuration looks like:
NUXt conguration options. (Large preview)
For the purpose of this tutorial, we do not need axios, linting and Prettier configurations.
Once that is done, we’ll run the following command in our terminal:
$ cd nUXt-tutorial-app$ npm run dev
Your app should now be running on http://localhost:3000 and this is what you should see:
NUXt scaffolding default landing page. (Large preview)
At this point, your app is ready for development.
Understanding Nuxt Folder Structure
Scaffolding the application as we did creates different files and folders which we can start working with. For someone who hasn’t work with NUXt before, this might throw you off balance. So we’ll be looking at the folders, getting to understand their importance.
Assets This folder is for un-compiled files such as images, font files, SASS, LESS or JavaScript files. Let us add create a styles folder and a main.css file and copy and paste the following in it.
a { text-decoration: none; color: inherit; cursor: pointer;}.header { width: 100%; max-width: 500px; margin-left: auto; margin-right: auto; height: 60px; top: 0; position: sticky; background-color: #fff; display: flex; justify-content: space-between; align-items: center;}.logo { width: 40%; max-width: 200px; height: 40px;}.logo .NUXtLogo { max-width: 30px; margin-left: 10px; max-height: 40px;}.nav { width: 60%; height: 40px; display: flex; justify-content: space-between; padding-right: 10px; max-width: 300px;}.nav__link { width: 80px; display: flex; align-items: center; border-radius: 4px; justify-content: center; height: 100%; border: 1px solid #00c58e; cursor: pointer;}.nav__link:active { background-color: #00c58e; border: 1px solid #00c58e; color: #fff; box-shadow: 5px 3px 5px 2px #3f41468c;}.home { padding-top: 30px;}.home__heading { text-align: center;}.directories { display: flex; box-sizing: border-box; padding: 10px; max-width: 1000px; margin: 0 auto; flex-wrap: wrap; justify-content: center;}@media (min-width: 768px) { .directories { justify-content: space-between; }}.directory__container { width: 100%; max-width: 220px; cursor: pointer; border-radius: 4px; border: 1px solid #00c58e; display: flex; height: 60px; margin: 10px 5px; margin-right: 0; justify-content: center; align-items: center;}.directory__name { text-align: center;}.directory { width: 100%; margin: 50px auto; max-width: 450px; border-radius: 4px; border: 1px solid #00c58e; box-sizing: border-box; padding: 10px 0;}.directory__info { padding-left: 10px; line-height: 22px; padding-right: 10px;}
The styles above will be used across the application for what we’ll be building. As you can see we have styles for the navigation and other aspects which we’ll plug into the application as we progress.
Components This folder is one we’re familiar with from Vue.js, it contains your reusable components.
Now, let’s create our first component and name it navBar.vue, and add the following code to it. We want the navbar of the site to display the logo and link to the Home and About pages which we will create in future. This navbar will be visible across the application. It will also make use of some styles that we have added above.
<template> <header class="header"> <div class="logo"> <nUXt-link to="/"> <Logo /> </nUXt-link> </div> <nav class="nav"> <div class="nav__link"> <nUXt-link to="/">Home</nUXt-link> </div> <div class="nav__link"> <nUXt-link to="/About">About</nUXt-link> </div> </nav> </header></template><script>import Logo from "@/components/Logo";export default { name: "nav-bar", components: { Logo }};</script><style></style>
The template section contains what will be visible to the user. We have a header element which contains our logo and nav links. For us to link to the pages, we make use of nUXt-link which provides navigation between component pages.
In the script section, we import the logo component using Nuxt alias @ and declared it in our component for use by adding it as a component. This makes it possible for us to render it in the template.
Layout Here, we’ll be storing our application layouts. This is particularly useful if your application’s design calls for two or more layouts, e.g. one for authenticated users and another for guests or admins. For the purpose of this tutorial, we’ll be sticking to the default layout.
Let us open our default.vue file and add our navBar component to the layout of our application.
<template> <div> <Nav /> <nUXt /> </div></template><script>import Nav from "~/components/navBar.vue";export default { components: { Nav }};</script>
In the template section, we’ve added our Nav component inside the layout container to always appear at the top after importing it into the file and declaring it in the script section.
The next thing after our Nav component is <nUXt />, which tells NUXt where to render all its routes.
This Nav component is the one we created above. By adding it here, the Nav component will be used across the application.
Middleware This folder was created to house JavaScript files that are required to run before a page(s) is rendered. If you’ve ever used the Vuejs navigation guard, this folder was created for files like that.
Pages This is another folder that developers with Vuejs background would not be familiar with. It works in such a way that every *.vue file is created as a route in your application so it serves as both views and a router folder at the same time, we’ll talk more about this in the next section.
Plugins This is where you store files that you want to run before mounting the root Vue.js application. It is not a required folder so it can be deleted.
nUXt.config.js This file is used to configure your application, it is usually pre-populated based on the config when creating your app. An ideal nUXt.config.js file should look like this by default:
export default { mode: 'universal', /* ** Headers of the page */ head: { title: process.env.npm_package_name || '', meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }, { hid: 'description', name: 'description', content: process.env.npm_package_description || '' } ], link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } ] }, /* ** Customize the progress-bar color */ loading: { color: '#fff' }, /* ** Global CSS */ css: [ ], /* ** Plugins to load before mounting the App */ plugins: [ ], /* ** NUXt.js dev-modules */ buildModules: [ ], /* ** NUXt.js modules */ modules: [ ], /* ** Build configuration */ build: { /* ** You can extend webpack config here */ extend (config, ctx) { } }}
Each time a change is made to this file, your application will automatically restart to reflect the changes. Let’s go over what the properties used in the file mean.
Mode The type of application; either universal or spa. By selecting universal, you’re telling NUXt that you want your app to be able to run on both the server-side and the client-side.
Head All the default meta tags properties and favicon link found inside the head tag in your app is found here. This is because NUXt.js doesn’t have a default index.html file, unlike Vue.js.
loading All NUXt applications come with a default loader component and the color can be customized here.
css You’re expected to enter the link to all your global CSS files so your application can take it into account when mounting the application. We’re going to add the link to our css file to this and restart our application.
/* ** Global CSS */ css: ["~/assets/styles/main.css"]
plugins This is where you connect all the plugins in your plugins folder to the application. It takes in an object with properties such as src that accepts the file path to the plugin and a mode that configures how your application treats such plugin; either as a server-side plugin or a client-side plugin. For example:
{ src: '~/plugins/universal-plugin.js' }, // for server and client plugins{ src: '~/plugins/client-side.js', mode: 'client' }, // for client only plugins{ src: '~/plugins/server-side.js', mode: 'server' }, // for server side only plugins
This is important to avoid error either on the server-side or client-side especially if your plugin requires something like localStorage that is not available on the server-side.
For more info about the nUXt.config.js file, check out the official doc.
Nuxt Pages And Routing System
The pages folder in your NUXt application is used to configure your application’s routes, i.e. your route name is dependent on the name of each file in this folder, e.g. if you have an about.vue file inside your pages file, it means you now have an /about route in your app, but that’s not all. What happens if you want a dynamic route for your application? Or a nested route? How do you go about it? let’s find out.
Basic Routes
Basic routes can be classified as routes that do not require extra configuration for them to work. For example, a direct route /work or a /contact route. So if your pages folder looks like this:
pages/--| me/ -----| index.vue -----| about.vue--| work.vue--| contact.vue--| index.vue
NUXt would automatically generate a router config that looks like this:
router: { routes: [ { name: 'index', path: '/', component: 'pages/index.vue' }, { name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' } ]}
These paths can then be used to access the components tied to them. You can see that the path does not contain pages. And NUXt handles the components named index.vue as it should without an additional config for that.
Nested Routes
To create a nested route, create a folder called dashboard inside the pages folder. This folder should contain all the files you want to nest in it. For example, user.vue and settings.vue. Then at the root of pages folder, create a file called dashboard.vue.
pages/ --| me/ -----| index.vue -----| about.vue --| dashboard/ -----| user.vue -----| settings.vue --| dashboard.vue --| work.vue --| contact.vue --| index.vue
This would automatically generate a router with routes that look like this:
router: { routes: [ { name: 'index', path: '/', component: 'pages/index.vue' }, { name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' }, { name: 'dashboard', path: '/dashboard', component: 'pages/dashboard.vue', children: [ { name: 'dashboard-user', path: '/dashboard/user', component: 'pages/dashboard/user.vue' }, { name: 'dashboard-settings', path: '/dashboard/settings', component: 'pages/dashboard/settings.vue' } ] } ]}
Notice that the route name always follows a regular pattern:
name of the folder + '-' + name of the file
With this, you can be sure that each route will have a unique name.
Dynamic Routes
Dynamic routes are routes that are defined by a variable, this variable can either be a name, number or an id gotten from client data on the app. This comes in handy when working with an API, where the id will likely be the id of the item coming from the database.
In NUXt, dynamic routes are defined by appending an _ to a file name or folder name in the pages folder. For instance, if you want a dynamic route whose variable name is id, all you need is to name your file _id.vue and NUXt automatically creates a dynamic route for you. For example:
pages/--| me/-----| index.vue-----| about.vue-----| _routeName-------| index.vue-------| info.vue--| dashboard/-----| user.vue-----| settings.vue--| dashboard.vue--| work.vue--| _id.vue--| contact.vue--| index.vue
This would automatically create a router file with the following routes,
{ name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'id', path: '/:id', component: 'pages/_id.vue' } { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' }, { name: 'me-routeName', path: '/me/:routeName', component: 'pages/me/_routeName/index.vue' }, { name: 'me-routeName-info', path: '/me/:routeName/info', component: 'pages/me/route.vue' }, { name: 'dashboard', path: '/dashboard', component: 'pages/dashboard.vue', children: [ { name: 'dashboard-user', path: '/dashboard/user', component: 'pages/dashboard/user.vue' }, { name: 'dashboard-settings', path: '/dashboard/settings', component: 'pages/dashboard/settings.vue' } ] } ]}
Although some of the Vue.js router tags work in NUXt and can be used interchangeably, it is recommended that we use NUXt router components. Here are some of the differences between the NUXt Router tags and Vue.js Router tags.
VueJsNUXtJSrouter-linknUXt-linkrouter-view (for nested routes)nUXt-childrouter-view(default)nUXt
Difference between vue.js router and nUXt.js router
At this point, Here’s what your app should look like this, with the navigation shown at the top.
The Landing page. (Large preview)
Now that we understand how NUXt pages and Routes work, let’s add our first page and route about.vue. This page would list some directories in the application with a link to a new page that shows more information about such directory.
Let us add the following code to it:
<template> <section class="home"> <h1 class="home__heading">About NUXtjs Directory Structure</h1> <div class="directories"> <div class="directory__container" v-for="directory in directories" :key="directory.id"> <p class="directory__name"> <nUXt-link :to="{ name: 'id', params: { id: directory.id, dir: directory } }" ></nUXt-link> </p> </div> </div> </section></template><script>export default { name: "about-nUXt", data() { return { directories: [ { id: 0, name: "The Assets Directory", info: "By default, NUXt uses vue-loader, file-loader and url-loader webpack loaders for strong assets serving. You can also use the static directory for static assets. This folder is for un-compiled files such as images, font files, SASS, LESS or JavaScript files" }, { id: 1, name: "The Components Directory", info: "The components directory contains your Vue.js Components. You can’t use asyncData in these components." }, { id: 2, name: "The Layouts Directory", info: "The layouts directory includes your application layouts. Layouts are used to change the look and feel of your page (for example by including a sidebar). Layouts are a great help when you want to change the look and feel of your NUXt.js app. Whether you want to include a sidebar or having distinct layouts for mobile and desktop" }, { id: 3, name: "The Middleware Directory", info: "The middleware directory contains your Application Middleware. Middleware lets you define custom functions that can be run before rendering either a page or a group of pages (layouts)." }, { id: 4, name: "The Pages Directory", info: "The pages directory contains your Application Views and Routes. The framework reads all the .vue files inside this directory and creates the application router. Every Page component is a Vue component but NUXt.js adds special attributes and functions to make the development of your universal application as easy as possible" }, { id: 5, name: "The Plugins Directory", info: "The plugins directory contains your Javascript plugins that you want to run before instantiating the root Vue.js Application. This is the place to register components globally and to inject functions or constants. NUXt.js allows you to define JavaScript plugins to be run before instantiating the root Vue.js Application. This is especially helpful when using your own libraries or external modules." }, { id: 6, name: "The Static Directory", info: "The static directory is directly mapped to the server root (/static/robots.txt is accessible under http://localhost:3000/robots.txt) and contains files that likely won’t be changed (e.g. the favicon). If you don’t want to use Webpack assets from the assets directory, you can create and use the static directory (in your project root folder)." }, { id: 7, name: "The Store Directory", info: "The store directory contains your Vuex Store files. The Vuex Store comes with NUXt.js out of the box but is disabled by default. Creating an index.js file in this directory enables the store. Using a store to manage the state is important for every big application. That’s why NUXt.js implements Vuex in its core." } ] }; }};</script><style></style>
Starting from the script section, we created an array which we store in the directories variable. Each array contains an object with id, name, and info. This is the data we’ll show to the user when this page is opened. We want to show it to the user such that the names are clickable.
We do that in the template section, using v-for to loop through the array. This makes it possible to get each item in the array, which we can access using directory. In the loop, we use nUXt-link to handle the linking of each time. Using nUXt-link, we pass the details (id, name and info) of each directory item via nUXt router. We do this because we want to be able to display this on the show page when the user clicks on an item.
If you navigate to the /about route using your browser, you should see something like this:
About page. (Large preview)
Now, let’s create a new file and name it _id.vue. This would automatically create a dynamic route that takes the id param from the link display a little information about any directory clicked on from the About page.
Let us add this to our file:
<template> <section class="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section></template><script>export default { name: "directory-info", data() { return { directory: this.$route.params.dir }; }};</script><style></style>
What we have done is to create a page that fetches data from the route param dir using the this.$route.params. This gets us the name and info of the clicked directory, which we then display to the user.
So if you click on any directory link (e.g. store directory), you should see this.
What the ID page looks like. (Large preview)
But there’s a problem, if you refresh this page, your directory info gets lost and you get an error. This would be fixed using our Vuex Store so let’s dive into it.
Using Vuex Store In Nuxt
Vuex can be accessed in NUXt using two modes:
Classic mode (deprecated).
Modules mode.
Modules mode
NUXt automatically creates a Store folder upon the creation of your app. In Modules mode, NUXt would treat every file inside this folder as a module but index.js is required for Vuex store to be activated in your app. So let’s create an index.js file in our store folder and set it up for use. Let us add the following to our file.
index.js
export const state = () => ({ }) export const getters = { } export const mutations = { } export const actions = { }
All we have done is to set up the store for our file with all we might need; the state for storing data, getters for performing extra manipulation to our state, mutations for modifying our state and actions for committing mutations.
NUXt also allows users to separate each core concept into different files which means we can have store.js, getters.js, mutation.js and action.js and this is good as it makes for easy maintainability. Now, we fix the problem of directory disappearing on refresh, we’ll use the store, but first, we need to install and set up Vuex persist for our store.
Install Vuex persist from npm using either command below, depending on your preference.
$ npm install --save vuex-persist
or
$ yarn add vuex-persist
After installing, we’re going to create a vuex-persist.js file in our plugins folder and add the following:
import VuexPersistence from 'vuex-persist' export default ({ store}) => { window.onNUXtReady(() => { new VuexPersistence({ storage: window.localStorage }).plugin(store); });}
Here, we import our plugin from node-modules and configure it to save your store in localStorage. This plugin allows you to choose other storage options such as sessionStorage too so feel free to explore their documentation for more info.
Remember to add it to your nUXt.config.js file.
/* ** Plugins to load before mounting the App */ plugins: [{ src: '~/plugins/vuex-persist', mode: 'client' }],
Here, we added the file path to our plugin and told NUXt to only run this plugin on the client side of this application.
Now, we can set our store up to accept and store directory info. Update your store to handle directory info like this:
export const state = () => ({ directory: ''})export const getters = {}export const mutations = { saveInfo(state, payload) { state.directory = payload.directory }}export const actions = {}
What we’ve done is to add a directory state to our store and a mutation function saveInfo that modifies the value of the directory state we added to our store in anticipation of the data we’d be passing it soon.
Next, in your about.vue file, update it to look like this.
<template> <section class="home"> <h1 class="home__heading">About NUXtjs Directory Structure</h1> <div class="directories"> <div class="directory__container" v-for="directory in directories" :key="directory.id" @click.prevent="storeDirectoryInfo(directory)" > <p class="directory__name"> <nUXt-link :to="{ name: 'id', params: { id: directory.id, dir: directory } }" ></nUXt-link> </p> </div> </div> </section></template><script>export default { name: "about-nUXt", data() { return { directories: [ //remains the same ] }; }, methods: { storeDirectoryInfo(dir) { this.$store.commit("saveInfo", { directory: dir }); } }};</script><style></style>
Now, we’ve added a click event to every directory container that passes the directory info as an argument to the storeDirectoryInfo. In this function, we commit the directory object to our store.
Finally, we would go back to our _id.vue file and replace the directory variable with our data from the store like this:
<template> <section class="directory" v-if="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section></template><script>import { mapState } from "vuex";export default { name: "directory-info", computed: { ...mapState(["directory"]) }};</script><style></style>
Here, we refactor our code to use directory object directly from our store by first importing mapState from Vuex.
import { mapState } from 'vuex';
Instead of first checking if this.$route.params.dir is undefined before accessing the data from our store, we decide to use our store by reading the data that’s in the store.
<script>import { mapState } from "vuex";export default { name: "directory-info", computed: { ...mapState(["directory"]) }};</script>
Then we update our template to make sure it doesn’t render while directory is undefined.
<template> <section class="directory" v-if="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section></template>
On doing this, no matter how many times we refresh our app, our directory object is safe in our store and can be easily accessed using the …mapState(['stateVariable']) method.
Deploying To Heroku
Now that our nUXt-tutorial-app app is complete, what’s next? Deploying our shiny new app to production.
We’ll be deploying our NUXt.js app to Heroku using Github for easy deployment so if you’ve not set up a repository for your app, now would be a time to do so. The next thing would be to open Heroku and create a new app, choose a name and connect it to GitHub and the repo created above. Next, go to your settings, you should see something like this.
Heroku App settings page. (Large preview)
Now, add the following config variables.
NPM_CONFIG_PRODUCTION=falseHOST=0.0.0.0NODE_ENV=production
The next thing we have to do is to create a Procfile in the root folder of our app (same level as nUXt.config.js) and enter this command:
web: nUXt start
This will run the nUXt start command and tell Heroku to direct external HTTP traffic to it.
After adding the Procfile to your app, commit and push your changes to your repo. If you have automatic deploys enabled for your app, your app should be live and accessible from its URL. If you can see your app live, congratulations! you have successfully built and deployed your first NUXt.js application.
Conclusion
Now that we know how to create a basic NUXt application and deploy to Heroku, what’s next? Here are some resources that cover things like using Axios in NUXt and implementing authentication in your app.
Using the axios module.
Implementing Authentication in Nuxt.
NUXt.js official documentation.
nUXt-tutorial-app Github repo.
(ks, ra, yk, il)
Website Design & SEO Delray Beach by DBL07.co
Delray Beach SEO
Via http://www.scpie.org/getting-started-with-nuxt/
source https://scpie.weebly.com/blog/getting-started-with-nuxt
0 notes
Text
Getting Started With Nuxt
About The Author
Front-end developer based in Lagos, Nigeria. He enjoys converting designs into code and building things for the web. More about Timi …
Developers often worry about the SEO Company of their SPAs (Single Page Applications) and how well they would do on Google searches (blogs, portfolio websites, product websites, and so on). Sometimes, they also worry about how complex building a server-side rendered application might be. In this tutorial, we’re going to learn how to create server-side rendered applications by using NUXt.js, how to configure your application for development, and how to deploy to Heroku.
Web developers build a lot of Single Page Applications using JavaScript frameworks (Angular, React, Vue). SPAs dynamically populate the contents of their pages on load which means by the time Google crawls their site, the important content is yet to be injected into the site. Part of this problem can be solved by pre-rendering your application’s content. This is where server-side applications come in, and for Vuejs developers, we can build server-side applications using NUXt.js.
We’re going to assume that you have not used it before, as such it will start from the ground-up — introducing you to NUXt.js, its file structure and how routing works. While also touching how you can get it to work with Vuex.
At the end of this tutorial, you should be able to go on to build basic web applications in NUXt.js, and if you have been wondering how to get started with NUXt.js, this will do justice to that.
This article is targeted at those that are fairly familiar with Vue.js and it’s a concept, For those without knowledge of Vue.js, consider starting from the official Vuejs documentation and The Net Ninja’s Vuejs playlist.
What Is Nuxt.js?
According to their official page:
“NUXt is a progressive framework based on Vue.js to create modern web applications. It is based on Vue.js official libraries (vue, vue-router and vuex) and powerful development tools (webpack, Babel and PostCSS). NUXt’s goal is to make web development powerful and performant with great developer experience in mind.”
It allows you to create three types of applications, depending on the purpose it’s intended for:
Static Generated pages (Pre-rendering) Static generated applications do not require API requests to fetch the contents of the pages, i.e. the contents are already included in the HTML file. An example of a static site is a portfolio website or a landing page for a product.
Single Page Application Most JavaScript frameworks (React, Angular, Emberjs, Vue, etc) are single page application whose contents are dynamically populated with faster transitions. Most SPAs make use of the HTML5 history API or the location Hash for routing.
Server Side Rendered Applications (SSR) Server-Side Rendering is a technique used to fetch and display client-side data on the server to send a fully rendered page to the client. This is a good approach to get good SEO Company for your application.
Creating Your First Nuxt.js Application
You can create a NUXt.js application in two ways:
Using the scaffolding tool create-nUXt-app.
From scratch.
In case you just want to see the finished app that we would be building, here’s a link to the GitHub repo.
In this tutorial, we would be focused on using create-nUXt-app so let’s get started. If you have npx installed, open your terminal and run this command:
$ npx create-nUXt-app nUXt-tutorial-app
or
$ yarn create nUXt-app nUXt-tutorial-app
For the purpose of this tutorial, nUXt-tutorial-app is the name of the application but feel free to name yours differently.
This would be followed by a list of options that help in configuring your application with what you might need for development.
Here’s what my configuration looks like:
NUXt conguration options. (Large preview)
For the purpose of this tutorial, we do not need axios, linting and Prettier configurations.
Once that is done, we’ll run the following command in our terminal:
$ cd nUXt-tutorial-app $ npm run dev
Your app should now be running on http://localhost:3000 and this is what you should see:
NUXt scaffolding default landing page. (Large preview)
At this point, your app is ready for development.
Understanding Nuxt Folder Structure
Scaffolding the application as we did creates different files and folders which we can start working with. For someone who hasn’t work with NUXt before, this might throw you off balance. So we’ll be looking at the folders, getting to understand their importance.
Assets This folder is for un-compiled files such as images, font files, SASS, LESS or JavaScript files. Let us add create a styles folder and a main.css file and copy and paste the following in it.
a { text-decoration: none; color: inherit; cursor: pointer; } .header { width: 100%; max-width: 500px; margin-left: auto; margin-right: auto; height: 60px; top: 0; position: sticky; background-color: #fff; display: flex; justify-content: space-between; align-items: center; } .logo { width: 40%; max-width: 200px; height: 40px; } .logo .NUXtLogo { max-width: 30px; margin-left: 10px; max-height: 40px; } .nav { width: 60%; height: 40px; display: flex; justify-content: space-between; padding-right: 10px; max-width: 300px; } .nav__link { width: 80px; display: flex; align-items: center; border-radius: 4px; justify-content: center; height: 100%; border: 1px solid #00c58e; cursor: pointer; } .nav__link:active { background-color: #00c58e; border: 1px solid #00c58e; color: #fff; box-shadow: 5px 3px 5px 2px #3f41468c; } .home { padding-top: 30px; } .home__heading { text-align: center; } .directories { display: flex; box-sizing: border-box; padding: 10px; max-width: 1000px; margin: 0 auto; flex-wrap: wrap; justify-content: center; } @media (min-width: 768px) { .directories { justify-content: space-between; } } .directory__container { width: 100%; max-width: 220px; cursor: pointer; border-radius: 4px; border: 1px solid #00c58e; display: flex; height: 60px; margin: 10px 5px; margin-right: 0; justify-content: center; align-items: center; } .directory__name { text-align: center; } .directory { width: 100%; margin: 50px auto; max-width: 450px; border-radius: 4px; border: 1px solid #00c58e; box-sizing: border-box; padding: 10px 0; } .directory__info { padding-left: 10px; line-height: 22px; padding-right: 10px; }
The styles above will be used across the application for what we’ll be building. As you can see we have styles for the navigation and other aspects which we’ll plug into the application as we progress.
Components This folder is one we’re familiar with from Vue.js, it contains your reusable components.
Now, let’s create our first component and name it navBar.vue, and add the following code to it. We want the navbar of the site to display the logo and link to the Home and About pages which we will create in future. This navbar will be visible across the application. It will also make use of some styles that we have added above.
<template> <header class="header"> <div class="logo"> <nUXt-link to="/"> <Logo /> </nUXt-link> </div> <nav class="nav"> <div class="nav__link"> <nUXt-link to="/">Home</nUXt-link> </div> <div class="nav__link"> <nUXt-link to="/About">About</nUXt-link> </div> </nav> </header> </template> <script> import Logo from "@/components/Logo"; export default { name: "nav-bar", components: { Logo } }; </script> <style> </style>
The template section contains what will be visible to the user. We have a header element which contains our logo and nav links. For us to link to the pages, we make use of nUXt-link which provides navigation between component pages.
In the script section, we import the logo component using Nuxt alias @ and declared it in our component for use by adding it as a component. This makes it possible for us to render it in the template.
Layout Here, we’ll be storing our application layouts. This is particularly useful if your application’s design calls for two or more layouts, e.g. one for authenticated users and another for guests or admins. For the purpose of this tutorial, we’ll be sticking to the default layout.
Let us open our default.vue file and add our navBar component to the layout of our application.
<template> <div> <Nav /> <nUXt /> </div> </template> <script> import Nav from "~/components/navBar.vue"; export default { components: { Nav } }; </script>
In the template section, we’ve added our Nav component inside the layout container to always appear at the top after importing it into the file and declaring it in the script section.
The next thing after our Nav component is <nUXt />, which tells NUXt where to render all its routes.
This Nav component is the one we created above. By adding it here, the Nav component will be used across the application.
Middleware This folder was created to house JavaScript files that are required to run before a page(s) is rendered. If you’ve ever used the Vuejs navigation guard, this folder was created for files like that.
Pages This is another folder that developers with Vuejs background would not be familiar with. It works in such a way that every *.vue file is created as a route in your application so it serves as both views and a router folder at the same time, we’ll talk more about this in the next section.
Plugins This is where you store files that you want to run before mounting the root Vue.js application. It is not a required folder so it can be deleted.
nUXt.config.js This file is used to configure your application, it is usually pre-populated based on the config when creating your app. An ideal nUXt.config.js file should look like this by default:
export default { mode: 'universal', /* ** Headers of the page */ head: { title: process.env.npm_package_name || '', meta: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1' }, { hid: 'description', name: 'description', content: process.env.npm_package_description || '' } ], link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } ] }, /* ** Customize the progress-bar color */ loading: { color: '#fff' }, /* ** Global CSS */ css: [ ], /* ** Plugins to load before mounting the App */ plugins: [ ], /* ** NUXt.js dev-modules */ buildModules: [ ], /* ** NUXt.js modules */ modules: [ ], /* ** Build configuration */ build: { /* ** You can extend webpack config here */ extend (config, ctx) { } } }
Each time a change is made to this file, your application will automatically restart to reflect the changes. Let’s go over what the properties used in the file mean.
Mode The type of application; either universal or spa. By selecting universal, you’re telling NUXt that you want your app to be able to run on both the server-side and the client-side.
Head All the default meta tags properties and favicon link found inside the head tag in your app is found here. This is because NUXt.js doesn’t have a default index.html file, unlike Vue.js.
loading All NUXt applications come with a default loader component and the color can be customized here.
css You’re expected to enter the link to all your global CSS files so your application can take it into account when mounting the application. We’re going to add the link to our css file to this and restart our application.
/* ** Global CSS */ css: ["~/assets/styles/main.css"]
plugins This is where you connect all the plugins in your plugins folder to the application. It takes in an object with properties such as src that accepts the file path to the plugin and a mode that configures how your application treats such plugin; either as a server-side plugin or a client-side plugin. For example:
{ src: '~/plugins/universal-plugin.js' }, // for server and client plugins { src: '~/plugins/client-side.js', mode: 'client' }, // for client only plugins { src: '~/plugins/server-side.js', mode: 'server' }, // for server side only plugins
This is important to avoid error either on the server-side or client-side especially if your plugin requires something like localStorage that is not available on the server-side.
For more info about the nUXt.config.js file, check out the official doc.
Nuxt Pages And Routing System
The pages folder in your NUXt application is used to configure your application’s routes, i.e. your route name is dependent on the name of each file in this folder, e.g. if you have an about.vue file inside your pages file, it means you now have an /about route in your app, but that’s not all. What happens if you want a dynamic route for your application? Or a nested route? How do you go about it? let’s find out.
Basic Routes
Basic routes can be classified as routes that do not require extra configuration for them to work. For example, a direct route /work or a /contact route. So if your pages folder looks like this:
pages/ --| me/ -----| index.vue -----| about.vue --| work.vue --| contact.vue --| index.vue
NUXt would automatically generate a router config that looks like this:
router: { routes: [ { name: 'index', path: '/', component: 'pages/index.vue' }, { name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' } ] }
These paths can then be used to access the components tied to them. You can see that the path does not contain pages. And NUXt handles the components named index.vue as it should without an additional config for that.
Nested Routes
To create a nested route, create a folder called dashboard inside the pages folder. This folder should contain all the files you want to nest in it. For example, user.vue and settings.vue. Then at the root of pages folder, create a file called dashboard.vue.
pages/ --| me/ -----| index.vue -----| about.vue --| dashboard/ -----| user.vue -----| settings.vue --| dashboard.vue --| work.vue --| contact.vue --| index.vue
This would automatically generate a router with routes that look like this:
router: { routes: [ { name: 'index', path: '/', component: 'pages/index.vue' }, { name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' }, { name: 'dashboard', path: '/dashboard', component: 'pages/dashboard.vue', children: [ { name: 'dashboard-user', path: '/dashboard/user', component: 'pages/dashboard/user.vue' }, { name: 'dashboard-settings', path: '/dashboard/settings', component: 'pages/dashboard/settings.vue' } ] } ] }
Notice that the route name always follows a regular pattern:
name of the folder + '-' + name of the file
With this, you can be sure that each route will have a unique name.
Dynamic Routes
Dynamic routes are routes that are defined by a variable, this variable can either be a name, number or an id gotten from client data on the app. This comes in handy when working with an API, where the id will likely be the id of the item coming from the database.
In NUXt, dynamic routes are defined by appending an _ to a file name or folder name in the pages folder. For instance, if you want a dynamic route whose variable name is id, all you need is to name your file _id.vue and NUXt automatically creates a dynamic route for you. For example:
pages/ --| me/ -----| index.vue -----| about.vue -----| _routeName -------| index.vue -------| info.vue --| dashboard/ -----| user.vue -----| settings.vue --| dashboard.vue --| work.vue --| _id.vue --| contact.vue --| index.vue
This would automatically create a router file with the following routes,
{ name: 'work', path: '/work', component: 'pages/work' }, { name: 'contact', path: '/contact', component: 'pages/contact' }, { name: 'id', path: '/:id', component: 'pages/_id.vue' } { name: 'me', path: '/me', component: 'pages/me/index.vue' }, { name: 'me-about', path: '/me/about', component: 'pages/me/about.vue' }, { name: 'me-routeName', path: '/me/:routeName', component: 'pages/me/_routeName/index.vue' }, { name: 'me-routeName-info', path: '/me/:routeName/info', component: 'pages/me/route.vue' }, { name: 'dashboard', path: '/dashboard', component: 'pages/dashboard.vue', children: [ { name: 'dashboard-user', path: '/dashboard/user', component: 'pages/dashboard/user.vue' }, { name: 'dashboard-settings', path: '/dashboard/settings', component: 'pages/dashboard/settings.vue' } ] } ] }
Although some of the Vue.js router tags work in NUXt and can be used interchangeably, it is recommended that we use NUXt router components. Here are some of the differences between the NUXt Router tags and Vue.js Router tags.
VueJs NUXtJS router-link nUXt-link router-view (for nested routes) nUXt-child router-view(default) nUXt
Difference between vue.js router and nUXt.js router
At this point, Here’s what your app should look like this, with the navigation shown at the top.
The Landing page. (Large preview)
Now that we understand how NUXt pages and Routes work, let’s add our first page and route about.vue. This page would list some directories in the application with a link to a new page that shows more information about such directory.
Let us add the following code to it:
<template> <section class="home"> <h1 class="home__heading">About NUXtjs Directory Structure</h1> <div class="directories"> <div class="directory__container" v-for="directory in directories" :key="directory.id"> <p class="directory__name"> <nUXt-link :to="{ name: 'id', params: { id: directory.id, dir: directory } }" ></nUXt-link> </p> </div> </div> </section> </template> <script> export default { name: "about-nUXt", data() { return { directories: [ { id: 0, name: "The Assets Directory", info: "By default, NUXt uses vue-loader, file-loader and url-loader webpack loaders for strong assets serving. You can also use the static directory for static assets. This folder is for un-compiled files such as images, font files, SASS, LESS or JavaScript files" }, { id: 1, name: "The Components Directory", info: "The components directory contains your Vue.js Components. You can’t use asyncData in these components." }, { id: 2, name: "The Layouts Directory", info: "The layouts directory includes your application layouts. Layouts are used to change the look and feel of your page (for example by including a sidebar). Layouts are a great help when you want to change the look and feel of your NUXt.js app. Whether you want to include a sidebar or having distinct layouts for mobile and desktop" }, { id: 3, name: "The Middleware Directory", info: "The middleware directory contains your Application Middleware. Middleware lets you define custom functions that can be run before rendering either a page or a group of pages (layouts)." }, { id: 4, name: "The Pages Directory", info: "The pages directory contains your Application Views and Routes. The framework reads all the .vue files inside this directory and creates the application router. Every Page component is a Vue component but NUXt.js adds special attributes and functions to make the development of your universal application as easy as possible" }, { id: 5, name: "The Plugins Directory", info: "The plugins directory contains your Javascript plugins that you want to run before instantiating the root Vue.js Application. This is the place to register components globally and to inject functions or constants. NUXt.js allows you to define JavaScript plugins to be run before instantiating the root Vue.js Application. This is especially helpful when using your own libraries or external modules." }, { id: 6, name: "The Static Directory", info: "The static directory is directly mapped to the server root (/static/robots.txt is accessible under http://localhost:3000/robots.txt) and contains files that likely won’t be changed (e.g. the favicon). If you don’t want to use Webpack assets from the assets directory, you can create and use the static directory (in your project root folder)." }, { id: 7, name: "The Store Directory", info: "The store directory contains your Vuex Store files. The Vuex Store comes with NUXt.js out of the box but is disabled by default. Creating an index.js file in this directory enables the store. Using a store to manage the state is important for every big application. That’s why NUXt.js implements Vuex in its core." } ] }; } }; </script> <style> </style>
Starting from the script section, we created an array which we store in the directories variable. Each array contains an object with id, name, and info. This is the data we’ll show to the user when this page is opened. We want to show it to the user such that the names are clickable.
We do that in the template section, using v-for to loop through the array. This makes it possible to get each item in the array, which we can access using directory. In the loop, we use nUXt-link to handle the linking of each time. Using nUXt-link, we pass the details (id, name and info) of each directory item via nUXt router. We do this because we want to be able to display this on the show page when the user clicks on an item.
If you navigate to the /about route using your browser, you should see something like this:
About page. (Large preview)
Now, let’s create a new file and name it _id.vue. This would automatically create a dynamic route that takes the id param from the link display a little information about any directory clicked on from the About page.
Let us add this to our file:
<template> <section class="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section> </template> <script> export default { name: "directory-info", data() { return { directory: this.$route.params.dir }; } }; </script> <style> </style>
What we have done is to create a page that fetches data from the route param dir using the this.$route.params. This gets us the name and info of the clicked directory, which we then display to the user.
So if you click on any directory link (e.g. store directory), you should see this.
What the ID page looks like. (Large preview)
But there’s a problem, if you refresh this page, your directory info gets lost and you get an error. This would be fixed using our Vuex Store so let’s dive into it.
Using Vuex Store In Nuxt
Vuex can be accessed in NUXt using two modes:
Classic mode (deprecated).
Modules mode.
Modules mode
NUXt automatically creates a Store folder upon the creation of your app. In Modules mode, NUXt would treat every file inside this folder as a module but index.js is required for Vuex store to be activated in your app. So let’s create an index.js file in our store folder and set it up for use. Let us add the following to our file.
index.js
export const state = () => ({ }) export const getters = { } export const mutations = { } export const actions = { }
All we have done is to set up the store for our file with all we might need; the state for storing data, getters for performing extra manipulation to our state, mutations for modifying our state and actions for committing mutations.
NUXt also allows users to separate each core concept into different files which means we can have store.js, getters.js, mutation.js and action.js and this is good as it makes for easy maintainability. Now, we fix the problem of directory disappearing on refresh, we’ll use the store, but first, we need to install and set up Vuex persist for our store.
Install Vuex persist from npm using either command below, depending on your preference.
$ npm install --save vuex-persist
or
$ yarn add vuex-persist
After installing, we’re going to create a vuex-persist.js file in our plugins folder and add the following:
import VuexPersistence from 'vuex-persist' export default ({ store }) => { window.onNUXtReady(() => { new VuexPersistence({ storage: window.localStorage }).plugin(store); }); }
Here, we import our plugin from node-modules and configure it to save your store in localStorage. This plugin allows you to choose other storage options such as sessionStorage too so feel free to explore their documentation for more info.
Remember to add it to your nUXt.config.js file.
/* ** Plugins to load before mounting the App */ plugins: [{ src: '~/plugins/vuex-persist', mode: 'client' }],
Here, we added the file path to our plugin and told NUXt to only run this plugin on the client side of this application.
Now, we can set our store up to accept and store directory info. Update your store to handle directory info like this:
export const state = () => ({ directory: '' }) export const getters = { } export const mutations = { saveInfo(state, payload) { state.directory = payload.directory } } export const actions = { }
What we’ve done is to add a directory state to our store and a mutation function saveInfo that modifies the value of the directory state we added to our store in anticipation of the data we’d be passing it soon.
Next, in your about.vue file, update it to look like this.
<template> <section class="home"> <h1 class="home__heading">About NUXtjs Directory Structure</h1> <div class="directories"> <div class="directory__container" v-for="directory in directories" :key="directory.id" @click.prevent="storeDirectoryInfo(directory)" > <p class="directory__name"> <nUXt-link :to="{ name: 'id', params: { id: directory.id, dir: directory } }" ></nUXt-link> </p> </div> </div> </section> </template> <script> export default { name: "about-nUXt", data() { return { directories: [ //remains the same ] }; }, methods: { storeDirectoryInfo(dir) { this.$store.commit("saveInfo", { directory: dir }); } } }; </script> <style> </style>
Now, we’ve added a click event to every directory container that passes the directory info as an argument to the storeDirectoryInfo. In this function, we commit the directory object to our store.
Finally, we would go back to our _id.vue file and replace the directory variable with our data from the store like this:
<template> <section class="directory" v-if="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section> </template> <script> import { mapState } from "vuex"; export default { name: "directory-info", computed: { ...mapState(["directory"]) } }; </script> <style></style>
Here, we refactor our code to use directory object directly from our store by first importing mapState from Vuex.
import { mapState } from 'vuex';
Instead of first checking if this.$route.params.dir is undefined before accessing the data from our store, we decide to use our store by reading the data that’s in the store.
<script> import { mapState } from "vuex"; export default { name: "directory-info", computed: { ...mapState(["directory"]) } }; </script>
Then we update our template to make sure it doesn’t render while directory is undefined.
<template> <section class="directory" v-if="directory"> <h1 class="directory__name"></h1> <p class="directory__info"></p> </section> </template>
On doing this, no matter how many times we refresh our app, our directory object is safe in our store and can be easily accessed using the …mapState(['stateVariable']) method.
Deploying To Heroku
Now that our nUXt-tutorial-app app is complete, what’s next? Deploying our shiny new app to production.
We’ll be deploying our NUXt.js app to Heroku using Github for easy deployment so if you’ve not set up a repository for your app, now would be a time to do so. The next thing would be to open Heroku and create a new app, choose a name and connect it to GitHub and the repo created above. Next, go to your settings, you should see something like this.
Heroku App settings page. (Large preview)
Now, add the following config variables.
NPM_CONFIG_PRODUCTION=false HOST=0.0.0.0 NODE_ENV=production
The next thing we have to do is to create a Procfile in the root folder of our app (same level as nUXt.config.js) and enter this command:
web: nUXt start
This will run the nUXt start command and tell Heroku to direct external HTTP traffic to it.
After adding the Procfile to your app, commit and push your changes to your repo. If you have automatic deploys enabled for your app, your app should be live and accessible from its URL. If you can see your app live, congratulations! you have successfully built and deployed your first NUXt.js application.
Conclusion
Now that we know how to create a basic NUXt application and deploy to Heroku, what’s next? Here are some resources that cover things like using Axios in NUXt and implementing authentication in your app.
Using the axios module.
Implementing Authentication in Nuxt.
NUXt.js official documentation.
nUXt-tutorial-app Github repo.
(ks, ra, yk, il)
Website Design & SEO Delray Beach by DBL07.co
Delray Beach SEO
source http://www.scpie.org/getting-started-with-nuxt/
0 notes
Text
Web Development
http://www.viralleakszone.com/web-development/
Web Development
Web Development
AJAX Tutorial
Amazon Web Services Tutorial
Angular Material
Angular 2
Angular 4
AngularJS Tutorial
Apache Tapestry
ASP.NET
Aurelia
Axure RP
BackboneJS Tutorial
Bootstrap Tutorial
CakePHP Tutorial
CherryPy
CodeIgniter
CoffeeScript
cPanel
CSS
CSS Buttons
D3.js Tutorial
DC.js
Django
Drupal
Electron
EmberJS Tutorial
ExpressJS Tutorial
ExtJS Tutorial
ES6 Tutorial
Firebase Tutorial
Flask Tutorial
Flex
Flexbox
Foundation
Framework7
FuelPHP
Google Maps
Grav
Grunt
Gulp
GWT
GWT Google Charts
GWT Highcharts
Highcharts
HTML
HTML5
HTTP
JasmineJS
Javascript
Joomla
jQuery
JqueryUI Tutorial
JavaServer Faces (JSF)
KnockoutJS
Koa.js
Laravel
Less
LeafletJS
MathML
0 notes
Text
5 Best JavaScript Frameworks in 2017
JavaScript popularity continues its rising. In 2016 we’ve witnessed such great changes, as AngularJS entire upgrade and introduction of Angular 2, ultimate dominating of jQuery that is applied on 96.5% of all JS sites, evolution of ECMAScript, two updates of Node.js in April and October accordingly, React finest hours, and even more. What to expect from 2017? — Here’s what we know so far: Angular 4 is expected in March 2017, ES2017edition is planned for mid-2017, Bootstrap v4 release should be anticipated this year as well.
Lately JavaScript was named among the best programming languages to learn in 2017 by IBM. At this stage it is used on both client- and server-sides and helps to design flavorful interfaces, enrich web apps with numerous functions and features, modify web pages in real time and much more.
In the meanwhile, JavaScript web frameworks can become a silver bullet for quick web app development. They serve as a skeleton for single page apps, allow developers to worry less about code structure or maintenance while focusing on creation of complex interface elements, and expand opportunities of JS and plain HTML.
The advantages of using JavaScript frameworks:
Efficiency — projects that used to take months and hundreds of lines of code now can be achieved much faster with well-structured prebuilt patterns and functions.
Safety — top javascript frameworks have firm security arrangements and are supported by large communities where members and users also act as testers.
Cost — most frameworks are open source and free. Since they help programmers to build custom solutions faster, the ultimate price for web app will be lower.
Best JavaScript frameworks in 2017:
Angular-s
After a long-awaited release of Angular back in 2016, its popularity has touched new heights, though AngularJS will hold off on giving ground in 2017.
Angular.js is often referred to as an MVW (Model-View-Whatever) framework and among the top benefits, for startups and mid-sized companies, people name: quick code production, easy testing of any app part and two-way data binding (changes in the backend are immediately reflected on the UI). Since release its ecosystem has gone beyond imagination. As for now, it is reasonably called the most used JS framework for SPAs (Single-Page Applications) development and it boasts the largest community of developers.
Angular2 comes with a long list of features that enable building everything, ranging from web to desktop and mobile. Framework is built with TypeScript from Microsoft with an eye to making JavaScript more agile and attractive for large enterprises. ng2 features a component-based architecture, improved DI (dependency injection), efficient logging service, inter-component communications and more.
Both Angular-s are a better option for enterprise-based applications or for strict programming environments with high standards for code readability.
ReactJS
We’ve already made React and Angular comparison, despite the fact that it is more of a library than a JS framework. It stands behind user interfaces of Facebook and Instagram, showing its efficiency within dynamic high-traffic applications.
It is rightly considered the fastest growing JS framework: as of today, there are about 1,000 contributors on Github. In MVC (Model-View-Controller) pattern React.js acts as “V” and can be smoothly integrated with any architecture. Due to the usage of virtual DOM it provides a great performance boost, comparing to Angular 1.x. In addition to that, React components can be created and re-used among applications or even transferred for public use.
Despite the fact that React has a higher learning curve, it makes app development straightforward and easy-to-understand. Furthermore it can be a perfect fit for complex, high-load and awesome software solutions.
Vue.js
Vue 2.0 was also introduced in 2016 and it took the best from Ember, React and Angular, putting all that into a handy package. It is proved to be faster and leaner, comparing to React and Angular 2.0.
Going deeper, Vue.js offers two-way data binding (seen in AngularJS), server-side rendering (like in Angular2 and ReactJS), Vue-cli (scaffolding tool for quick start) and optional JSX support. Its founder states that Vue 2 is one of the fastest frameworks all in all.
Vue.js is a better choice for quick development of cross-platform solutions. It can become a firm basis for high-end single page applications (SPAs) and beneficial solution to those cases, when performance is put ahead of good code organization or app structure.
Ember.js
Back in 2015 Ember was called the best javascript framework for web application, leaving behind React and AngularJS. Today it boasts a huge online community, regular updates and wide appliance of JavaScript best practices to guarantee ultimate experience right out of the box.
Ember features two-way data binding, like Angular.js, keeping both view and model in sync for all the time. Applying Fastboot.js module it ensures prompt server-side rendering of DOM, improving performance of complex UIs.
Emberjs is commonly usable for complex feature-rich web applications and website. Among the top users are Chipotle, Blue Apron, Nordstrom, Kickstarter, LinkedIn, Netflix and many others. Moreover it has an easier learning curve and there are oceans of tutorials and guide available online.
Meteor.js
Meteor is among the most popular JavaScript frameworks but which comes well-heeled with tons of features for back-end development, front-end rendering, database management and business logic. Since release in 2012 its ecosystem has grown drastically and at a swift rate.
This full-stack platform enables fast development of end-to-end web and mobile applications in pure JavaScript. Due to modular structure all the packages and libraries can be used at pace. In terms of performance, all the changes in the database are immediately transmitted to the UI and in conversely with no evident time losses caused by different languages or server response time.
MeteorJS covers all the phases of software development cycle and takes care of such glooming processes as linking, files concatenation and others. It is of current usage in real-time application development for business companies like Mazda, IKEA, Honeywell and many others.
from Blogger http://ift.tt/2x3pfKn via IFTTT
0 notes
Text
ember.js interview questions
complete notes on ember.js, complete notes on emberjs, complete tutorials on ember.js, complete tutorials on emberjs, ember.js notes, ember.js questions asked in companies, ember.js questions asked in interview, ember.js questions asked in mnc, ember.js questions for interview, ember.js tutorials, emberjs notes, emberjs questions asked in companies, emberjs questions asked in interview, emberjs questions asked in mnc, emberjs questions for interview, emberjs tutorials, faq for ember.js, faq for emberjs, faq on ember.js, faq on emberjs, interview questions on ember.js, interview questions on emberjs, latest interview questions on ember.js, latest interview questions on emberjs, most asked ember.js interview questions, most asked emberjs interview questions, notes on ember.js, notes on emberjs, rapid fire on ember.js, rapid fire on emberjs, rapid fire questions on ember.js, rapid fire questions on emberjs, top interview questions on ember.js, top interview questions on emberjs, tutorials on ember.js, tutorials on emberjs, updated interview questions answers on ember.js, updated interview questions answers on emberjs, ember.js interview questions
0 notes
Text
Five Superb 2017 JavaScript Frameworks

This location up at first appeared on DA-14 web-site. Appear at the quite initially write-up beneath.
JS acceptance carries on its climbing. In 2016 now we have witnessed these sorts of great variations, as
AngularJS complete enhance and introduction of Angular two, supreme dominating of framework jQuery
which could be made use of on 96.5% of all JS internet sites, two updates of framework Node.js, evolution
and updates of ECMA Script and Oct effectively, Reply exceptionally suitable a lot of hrs, too as in quite a
few disorders extra. What to foresee from 2017?
Presently JS was named the ideal language to understand in 2017. In the minute it is actually definitely
made use of on every of individuals client and server sides, might help to structure and class interfaces,
enrich total entire world extensive world-wide- web apps with a lot of characteristics and abilities, modify
webpage in responsible time and far a whole lot additional.
Along with though within the meantime, JS website frameworks perhaps acquire into a silver bullet for
rapid world-wide- web software program enhancement. They operation a skeleton for anyone internet site
applications, allow for for builders to tension significantly a good deal a lot less about code composition or
servicing even though specializing in improvement of elaborate many elements of interface, and create
prospects of JS and easy HTML.
The benefits of utilizing JS frameworks:
Security - main JS FWs have agency protection preparations and they are now supported by huge
communities by which associates and people also perform as checkers.
Achievements - tasks that utilised to get months and countless traces of code now is usually attained
considerably a lot a lot quicker with perfectly structured designs and attributes.
Price tag - most FWs are open up up supply and cost-free. Contemplating the fact that they realy help
programmers to construct individualized techniques more speedily, the final word phrase promoting fee for
website program will probable be cut down.
Actually best JS frameworks in 2017:
ReactJS
We have by now developed Respond, recognized basic simple fact that it certainly is supplemental along
with the library rather than standard JS framework. It stands guiding consumer interfaces of both Facebook
and Instagram, demonstrating its effectiveness inside of just dynamic high-traffic apps.
It actually is rightly regarded as the swiftest attaining JS framework: as of presently, you could possibly
appear throughout about one particular unique contributors on Github. In MVC sample Respond.js
functions as “V” and may be effortlessly built-in with kindly any architecture. Because of to for that use of
digital DOM it offers an incredible common total overall performance elevate, examining to Angular
anyone.x. Coupled with that, Respond to options may be made and re-used between offers or possibly
transferred for usual normal general public use.
Regardless of the indisputable fact that Respond to incorporate an even much larger buying out curve, it
could make software program improvement uncomplicated and easy-to- understand. On top of that to that
it'd be an outstanding in excellent ailment for intricate, high-load and marvelous application responses.
AngularJs
Future get started of Angular another time in 2016, its diploma of attractiveness has touched pretty new
heights, although AngularJS will keep off on supplying flooring in 2017.
Angular.js - usually normally generally known as MVW FW. Amid the perfect optimistic aspects, for startups
and middle sized businesses, people title: fast code advancement, straightforward screening of any
program portion and two-way particulars binding (enhancements during backend process are straight away
mirrored regarding the UI). Owing on your real truth get started its ecosystem has considerable extensive
long gone further more extra than creativeness. As for now, it is actually really in actual fact somewhat
referred to as probably fairly maybe by far the most utilised FW for SPAs advancement and it offers a vital
group of builders.
Meteor.js
Framework is quite possibly the most well-liked JS FWs which arrives well-heeled with tons of properties
for backend progression, frontend rendering, databases administration and agency logic. Just because
begin in 2012 its ecosystem has produced substantially and while in the swift price.
This full-stack system causes it to be feasible for swift development of end-to- end net and cellular classes in
pure JS. Lots of many thanks to modular design and style each and every from the offers and libraries may
be utilised at price. Close to procedure, the varied enhancements within the databases are straight away
transmitted into your UI also as in conversely devoid of attaining obvious time losses induced by many
languages or server reaction time.
MeteorJS addresses a great deal of the phases of application advancement cycle and will pick out
treatment of this kind of glooming techniques as linking, knowledge concatenation and other gentlemen
and ladies. It is actually in fact primarily of present-day utilization in real-time personal computer
application enhancement for company organizations: Mazda, Honeywell and plenty of other folks.
Vue.js
Vue two.0 was born in 2016 and it took one of several most powerful from Ember, Reply and Angular,
inserting all of that acceptable ideal right into a simple give. It is actually proved to get more speedily and
leaner, examining to Respond to and Angular two.0.
Probable further more additional, Vue.js alternatives two-way details binding (noticed in AngularJS), server-
side rendering, Vue-cli and also optional JSX guidance. Its founder states that Vue two is among the
quickest frameworks.
Vue.js is the truth is a much larger drive for fast progression of crossplatform opportunities. It may well
effectively pretty perhaps mature for being a agency foundation for high end solitary webpage purposes
(SPAs) and cherished option to these people today eventualities, when common effectiveness is spot
beforehand of superb code firm or application framework.
Ember.js
Back again yet again over again in 2015 Ember was named pretty quite possibly one of the most useful
framework for internet software program plan, forsaking Reply and AngularJS. Right now it features an
infinite on-line community women and men, repeated updates and massive equipment of JS really greatest
strategies to get confident supreme comprehending fantastic outside the house your house of the box.
Ember attributes two-way experience binding - like Angular.js, retaining pretty much each individual check
out out out and structure in sync for almost each and every of the time. Employing Fastboot.js module it
guarantees prompt DOM rendering, escalating efficiency of modern UIs.
Emberjs is usually usable for subtle feature-rich on the net programs and on the net website page. Between
the ideal clients: Kickstarter, Nordstrom, LinkedIn. Also it is actually actually a significantly far better
acquiring out curve and you may obtain many tutorials and information in existence on line.
Summary
Using a determination throughout the great JS framework just is not about skills that every can present. It is
dependent on preliminary company courses, enterprise technological specs, widespread framework
usefulness as well as the way it would be utilized inside of every particular point out of affairs.
0 notes
Text
updated interview questions answers on ember.js
complete notes on ember.js, complete notes on emberjs, complete tutorials on ember.js, complete tutorials on emberjs, ember.js notes, ember.js questions asked in companies, ember.js questions asked in interview, ember.js questions asked in mnc, ember.js questions for interview, ember.js tutorials, emberjs notes, emberjs questions asked in companies, emberjs questions asked in interview, emberjs questions asked in mnc, emberjs questions for interview, emberjs tutorials, faq for ember.js, faq for emberjs, faq on ember.js, faq on emberjs, interview questions on ember.js, interview questions on emberjs, latest interview questions on ember.js, latest interview questions on emberjs, most asked ember.js interview questions, most asked emberjs interview questions, notes on ember.js, notes on emberjs, rapid fire on ember.js, rapid fire on emberjs, rapid fire questions on ember.js, rapid fire questions on emberjs, top interview questions on ember.js, top interview questions on emberjs, tutorials on ember.js, tutorials on emberjs, updated interview questions answers on ember.js, updated interview questions answers on emberjs, ember.js interview questions
0 notes
Text
tutorials on ember.js
complete notes on ember.js, complete notes on emberjs, complete tutorials on ember.js, complete tutorials on emberjs, ember.js notes, ember.js questions asked in companies, ember.js questions asked in interview, ember.js questions asked in mnc, ember.js questions for interview, ember.js tutorials, emberjs notes, emberjs questions asked in companies, emberjs questions asked in interview, emberjs questions asked in mnc, emberjs questions for interview, emberjs tutorials, faq for ember.js, faq for emberjs, faq on ember.js, faq on emberjs, interview questions on ember.js, interview questions on emberjs, latest interview questions on ember.js, latest interview questions on emberjs, most asked ember.js interview questions, most asked emberjs interview questions, notes on ember.js, notes on emberjs, rapid fire on ember.js, rapid fire on emberjs, rapid fire questions on ember.js, rapid fire questions on emberjs, top interview questions on ember.js, top interview questions on emberjs, tutorials on ember.js, tutorials on emberjs, updated interview questions answers on ember.js, updated interview questions answers on emberjs, ember.js interview questions
0 notes
Text
top interview questions on ember.js
complete notes on ember.js, complete notes on emberjs, complete tutorials on ember.js, complete tutorials on emberjs, ember.js notes, ember.js questions asked in companies, ember.js questions asked in interview, ember.js questions asked in mnc, ember.js questions for interview, ember.js tutorials, emberjs notes, emberjs questions asked in companies, emberjs questions asked in interview, emberjs questions asked in mnc, emberjs questions for interview, emberjs tutorials, faq for ember.js, faq for emberjs, faq on ember.js, faq on emberjs, interview questions on ember.js, interview questions on emberjs, latest interview questions on ember.js, latest interview questions on emberjs, most asked ember.js interview questions, most asked emberjs interview questions, notes on ember.js, notes on emberjs, rapid fire on ember.js, rapid fire on emberjs, rapid fire questions on ember.js, rapid fire questions on emberjs, top interview questions on ember.js, top interview questions on emberjs, tutorials on ember.js, tutorials on emberjs, updated interview questions answers on ember.js, updated interview questions answers on emberjs, ember.js interview questions
0 notes
Text
rapid fire questions on emberjs
complete notes on ember.js, complete notes on emberjs, complete tutorials on ember.js, complete tutorials on emberjs, ember.js notes, ember.js questions asked in companies, ember.js questions asked in interview, ember.js questions asked in mnc, ember.js questions for interview, ember.js tutorials, emberjs notes, emberjs questions asked in companies, emberjs questions asked in interview, emberjs questions asked in mnc, emberjs questions for interview, emberjs tutorials, faq for ember.js, faq for emberjs, faq on ember.js, faq on emberjs, interview questions on ember.js, interview questions on emberjs, latest interview questions on ember.js, latest interview questions on emberjs, most asked ember.js interview questions, most asked emberjs interview questions, notes on ember.js, notes on emberjs, rapid fire on ember.js, rapid fire on emberjs, rapid fire questions on ember.js, rapid fire questions on emberjs, top interview questions on ember.js, top interview questions on emberjs, tutorials on ember.js, tutorials on emberjs, updated interview questions answers on ember.js, updated interview questions answers on emberjs, ember.js interview questions
0 notes
Text
rapid fire questions on ember.js
complete notes on ember.js, complete notes on emberjs, complete tutorials on ember.js, complete tutorials on emberjs, ember.js notes, ember.js questions asked in companies, ember.js questions asked in interview, ember.js questions asked in mnc, ember.js questions for interview, ember.js tutorials, emberjs notes, emberjs questions asked in companies, emberjs questions asked in interview, emberjs questions asked in mnc, emberjs questions for interview, emberjs tutorials, faq for ember.js, faq for emberjs, faq on ember.js, faq on emberjs, interview questions on ember.js, interview questions on emberjs, latest interview questions on ember.js, latest interview questions on emberjs, most asked ember.js interview questions, most asked emberjs interview questions, notes on ember.js, notes on emberjs, rapid fire on ember.js, rapid fire on emberjs, rapid fire questions on ember.js, rapid fire questions on emberjs, top interview questions on ember.js, top interview questions on emberjs, tutorials on ember.js, tutorials on emberjs, updated interview questions answers on ember.js, updated interview questions answers on emberjs, ember.js interview questions
0 notes