Vue.js, Vuex, Vuetify & Nuxt.js
What is Vue.js?
Vue.js is a progressive framework for JavaScript used to build web interfaces and one-page applications. Not just for web interfaces, Vue.js is also used both for desktop and mobile app development with Electron framework. The HTML extension and the JS base quickly made Vue a favored front-end tool, evidenced by adoption by such giants as Adobe, Behance, Alibaba, Gitlab, and Xiaomi.
Unlike other monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable. The core library is focused on the view layer only, and is easy to pick up and integrate with other libraries or existing projects.
How to get started with Vue and installation you can directly go to Vue official site Vue.js. In this blog we are going to cover main topics like Plugins, Css, Vuex, Vuetify and Nuxt implementation in Vue.
Vue Ecosystem
It has a rich ecosystem of official core libraries, great developer tooling support, a galaxy of third party plugins, developer tutorials and a matured ecosystem of related component frameworks, such as Vuetify, BootstrapVue, Element, Quasar, NativeScript-Vue , Nuxt.js, VuePress and many more which you may want to pick and choose based on the needs of your application.
Some of the core libraries maintained by Vue team are as follows with their links.
- Vue Router (https://router.vuejs.org/)
- Vuex (https://vuex.vuejs.org/)
- Vue Loader (https://vue-loader.vuejs.org)
- Vue Server Renderer (https://ssr.vuejs.org/)
- Vue Test Utils (https://vue-test-utils.vuejs.org/)
- Vue Dev-Tools (https://github.com/vuejs/vue-devtools)
- Vue CLI (https://cli.vuejs.org/)
Directory Structure of Vue CLI
- /rootFolderName/public
- /rootFolderName/src
- /rootFolderName/rootFiles mentioned in the image
Directory Structure of Vue & Nuxt
Vue.js File
- <template>: This section contain all template/design layer of code
- <script>: This section contain all scripts and functionality required to manipulate data or to perform actions on component click etc.
- <style>: This section contain styling of the page or template.
Helpers in Vue
capitalize, normalize or dasherize functions or date manipulation. Thereby we do not need to define these type of functions again and again on each page, we can simply put common functions inside /src/helpers/helperFileName and can access them globally in the current project folder anywhere requried.How to use Helpers in Vue?
- Create a helper filer inside /src/helpers folder for e.g. string-helpers.js and write functions inside this file like in a below screenshot -
- Now use this helpers whenever it is required just by importing the helper file in the file you want to use it like -
Generic Component in Vue
- Create a new file inside /src/components and named it as genericButton.vue
- Now add template for this component and props we required as below (genericButton.vue)
- Now use this genericButton inside page or another component here we are going to use this inside /src/pages created a new file named as display.vue & import the genericButton.vue from /src/components/genericButton.vue like as below (display.vue)
Plugins in Vue
How to add 3rd party plugin in Vue-CLI?
How to add 3rd party plugin in Nuxt?
mode property ('client' or 'server') in plugins
Plugins Available in Vue
- animate.css It is a library of ready-to-use, cross-browser animations for use in your web projects. Great for emphasis, home pages, sliders, and attention-guiding hints.
- vue-apexcharts It is a wrapper component for ApexCharts ready to be integrated into your vue.js application to create stunning Vue Charts.
- vue-echart It is a wrapper for eCharts to allow it to work in the Vue environment.
- moment Parse, validate, manipulate, and display dates in JavaScript with moment package, this component provide you the handy moment.js filter to use in your vue.js project.
- vue2-google-maps It comes with a well-rounded set of components for interacting with Google Maps as well as two-way data binding
- vue-gtag The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform
- vue-head Manipulating the meta information of the head tag, a simple and easy way.
- vue-i18n is internationalization plugin of Vue.js. It easily integrates some localization features to your Vue.js Application
- vue-shortkey Accepts shortcuts globally and in a single listener. Easy keyboard shortcuts.
- vuetify is a Vue UI Library with beautifully handcrafted Material Components. No design skills required — everything you need to create amazing applications is at your fingertips.
- vuex-persist A Typescript-ready Vuex plugin that enables you to save the state of your app to a persisted storage like Cookies or localStorage.
- vue-axios A small wrapper for integrating axios to Vuejs CLI
- @nuxtjs/axios A secure and easy integration of axios in Nuxt
- firebase The Firebase JavaScript SDK implements the client-side libraries used by applications using Firebase services
- vee-validate Form Validation for Vue.js
How to Use CSS in Vue
Here v-data-table is a vuetify component and if we make any change in this component CSS without using scoped it will be reflected in all other pages as well wherever v-data-table is used.
Another important point to be remembered whenever we use inline CSS to modify the existing CSS class of the component like Vuetify components we need to used the Extraction operator >>> before the class if that class is not a parent class of the component and if CSS changes not reflected on page.
For e.g.
- Create a new folder inside /src/assets/ named it as css or scss/sass whatever styling you are using for better naming convention.
- Create a .css, .scss, or .sasss file inside the newly created folder and define all styling do you want to use globally. For e.g. in the given screenshot we are using scss files and all files are imported inside the main scss file which is theme.scsss here.
Note: We can overrides existing component style and add on additional library variables for the same for e.g. here we are using Vuetify components.Variable Style File Overrides Style File Main Style File - Now we need to config style for global access for that we have different approaches which is based on that are we using Vue CLI or Nuxt?.
I. In Vue CLI - Import variables inside vue.config.js & import main theme scss inside main.jsvue.config.js 
main.js
CSS is the most important web technologies that are widely used along with HTML and JavaScript. CSS have file extension of .css;
- Sophisticated.
- Works with Integration with HTML.
- It consist declarative and selective block where dilaceration consist of semicolon
- It does not allow use of variable like in sass and scss.
Example of Css
SASS: Sass is derived from another pre-processor known as Haml. It was designed and written by Ruby developers so;
SCSS provides the CSS friendly syntax to closing the gap between Sass and CSS. So;
What is Vuex?
- The state, which is the source of truth that drives our app;
- The view, which is just a declarative mapping of the state;
- The actions, which are the possible ways the state could change in reaction to user inputs from the view.
- Instead of mutating the state, actions commit mutations.
- Actions can contain arbitrary asynchronous operations,
How to use Vuex in Vue?
- In Vue CLI: You need to install the Vuex to the app Click here to know more.
- In Nuxt: The
storedirectory contains your Vuex Store files. The Vuex Store comes with Nuxt.js out of the box but is disabled by default. Creating anindex.jsfile in this directory enables the store Click here to know more.
What is Vuetify?
- Usage and Examples: In this you can check the component usage with different examples
- API: In this you can access all Props, Sass Variables, Events, and Slots are available related to the particular component.
What is NUXT?
How to setup Nuxt?
Features of Nuxt?
- Server-side
rendered sites are rendered on the server each time the user requests a page,
therefore a server is needed to be able to serve the page on each request.
- Static
sites are very similar to server-side rendered applications with the main
difference being that static sites are rendered at build time, therefore no
server is needed. Navigating from one page to another is then on the client-side.
- Client
side rendering only there is no server-side rendering. Client side rendering
means rendering the content in the browser using JavaScript. Instead of getting
all of the content from the HTML we just get a basic HTML document with a
JavaScript file that will then render the rest of the site using the browser.
For client side rendering set ssr to false in nuxt.config.js file.
- Data Fetching Nuxt.js supports traditional Vue patterns for loading data
in your client-side app, such as fetching data in a component's mounted() hook.
Universal apps, however, need to use Nuxt.js-specific hooks to be able to
render data during server-side rendering. This allows your page to render with
all of its required data present.
Nuxt has two hooks for asynchronous data loading:
I. The fetch hook (Nuxt 2.12+). This hook can be placed on any component, and provides shortcuts for rendering loading states (during client-side rendering) and errors.
II. The asyncData hook. This hook can only be placed on page components. Unlike fetch, this hook does not display a loading placeholder during client-side rendering: instead, this hook blocks route navigation until it is resolved, displaying a page error if it fails. Static Hosting statically render your Nuxt.js application and get all of the benefits of a universal app without a server. The nuxt generate command will generate a static version of your website. It will generate HTML for every one of your routes and put it inside of its own file in the dist/ directory. This improves performance as well as SEO and better offline support.
Server Hosting is server-side rendering also known as SSR means that your page is rendered on the server when it is requested by the user. When the user opens your page in a browser the browser sends a request to the server requesting that page. The page is rendered on the server and sent back to the browser with all its content.
File System Routing Nuxt.js automatically generates the vue-router configuration based on your file tree of Vue files inside the pages directory. When you create a .vue file in your pages directory you will have basic routing working with no extra configuration needed.
Meta tags and SEO Nuxt.js gives you 3 different ways to add meta data to your application:
I. Globally using the nuxt.config.js
II. Locally using the head as an object
III. Locally using the head as a function so that you have access to data and computed properties- Configuration by
default, Nuxt.js is configured to cover most use cases. This default
configuration can be overwritten with the nuxt.config.js file.
- Loading Nuxt.js gives you its own loading progress bar component
that's shown between routes. You can customize it, disable it or even create
your own loading component.
- Component Nuxt.js comes with a few important components included out
of the box, which will be helpful when building your application. The
components are globally available, which means that you don't need to import
them in order to use them for e.g. <Nuxt/>.
- Transitions Nuxt.js
uses the transition component to let you create amazing transitions or animations
between your routes. To define a custom transition for a specific route adds
the transition key to the page component.
- Preview Mode With Nuxt.js and full static you can now use live preview which will call your API or your CMS so you can see the changes live before deploying.
Miscellaneous Topics
- Vue Lifecyle - https://www.digitalocean.com/community/tutorials/vuejs-component-lifecycle
- Vue Best Framework - https://madewithvuejs.com/blog/the-best-vue-js-frameworks
- Vue Component Libraries - https://athemes.com/collections/vue-ui-component-libraries/










Comments
Post a Comment