Hello, world.
This is a blog about application development web, desktop & mobile across a range of programming languages incl. JavaScript, C# and more.
These are interesting times for the web. Tag along as I get amazed on what the web can do, how AI is taking over the world, and sympathize my spectacular failures and stupidity.
Explore
- 📝 Posts — In-depth articles on web development, JavaScript, TypeScript, Vue.js, ASP.NET, and more
- 🗂️ Categories — Browse topics: JavaScript, Vue.js, TypeScript, ASP.NET, and more
- 🚀 Apps — Simple, powerful tools built for real-world use
Stay in touch!: 🐤Twitter | 🛜RSS | 🚀GitHub
I recently ended up with a low-end box with CentOS 7. After a long, long time, I got to try out skills on anything other than a managed Ubuntu / RHEL / Windows server/client. The fact that the box depended on me to get the app running was exciting but scary.
After some fidgeting around, I got down to business with getting the basic OS configured. It was time to install NodeJS.
...
There are three main ways to store variables and/or react to variable changes in Vue components.
data computed Watch for changes in watcher So, how to decide when to use what? (that is 3-in-1 question, I outwit myself)
Although these sections look similar, they serve different functions. Evaluate the variables against the following considerations when you are in doubt.
Description Data Computed Watcher Store variables Store local variables Computed variables. Can be static, derived from other variables, or can be static functions Does not store variables - only watches them. React to variable value changes Y Y Y Cached? Y Y N/A Scope Local to component Local to component, but can derive/make calculations with variables from props, store, etc. Can watch local or store variables and react to changes Can be referred by <template> Y e.g. {{ myName }} Y {{ myCalcName }} N/A Can be referred by <script> methods Y this.myName Y this.myCalcName N/A Perform action when value changes N N Y Consequence of a value change Change UI to react to change Change UI Perform action - local/vuex Can change other variable values N Y Y See examples below.
...
Vue provides one excellent way and three other alternative ways of getting your components to work together to form one beautiful, seamless application. Let us look at them one by one :)
1. Vuex Yesterday we talked about Vuex and how we (try to) manage vuex variables and local variables in a Vue component. What we did not talk about was how Vuex is the most effective solution for all inter-component communications.
...
Vuex is quite a powerful way of storing variables and sharing them across components, but where do you draw the line? Which variables do you store locally and which of them are shifted to Vuex store?
This is the advise I often come across -
Get your variables in store; keep component clean and consider future reuse Don’t overdo Vuex. Apply judgment and use store judiciously I find that the code I write oscillates between the two with no practical standard that I can apply across the team.
...
Vue allows us to build out infinite blocks of components that can work together or build on top of another to provide UIs of increasing sophistication. You may have a page or view that loads dozens of components including fields, tabs, charts and so on, and the loading of such components is automatically taken care by Vue.
Consider this simple example that uses Vuetify and Vue - Todo view, which is the base view to show to-dos.
...
Search in Vuetify data tables is just beautiful. Define a data table and a search is readily available for you. What else can a human ask for?
In fact, data tables were the single biggest reason for me to choose Vuetify about an year back. My long term association with data-driven application means that I am ever-so-dependent on the data table functionality.
Many other libraries in the market need you to implement search by yourself. Although not a big deal (the code is highly reusable), it is nice to not worry about yet another feature for once.
...
Let us see how we can easily accumulate requests when user types in a search (or auto-complete) fields and collate them in one go.
When implementing the ‘instant search’ fields in Vue, the cycle of events is pretty standard -
User keys in characters System keeps getting those characters and sending them to the server for processing System reacts to changes from server and displays search results The same cycle repeats for fields include auto-complete that take user action and return stuff from server.
...
Vue filters provide an excellent way to format data on the UI. Define Vue filters using a filter: block in single file components, or use global filters.
Consider the following use cases -
Purchase date is stored in yyyy-mm-dd in DB, but you have to display dd-mm-yyyy format Cost data needs to be displayed in currency of user’s locale Apply separators in bill number for better readability These and many more are easily accomplished in Vue filters. Let us consider an example of formatting numbers in currency.
...
You find forms everywhere in a data-driven application. Forms, as a rule, need some validation on the client-side to nudge users to fill in data in line with what we want. These validation are easy to implement in Vue.
Consider an example that includes Vuetify for styling the UI -
<template> <div> <v-form ref="form" v-model="valid"> <v-layout row wrap> <v-flex xs12></v-flex> <v-flex xs12> <v-text-field v-model="userId" label="Full Name" :rules="[rules.required, rules.min8Chars]" ></v-text-field> </v-flex> <v-flex xs12> <v-text-field v-model="userEmail" label="Enter your e-mail" :rules="[rules.required, rules.email]" ></v-text-field> </v-flex> <!-- not used. demonstrates that user cannot submit form unless valid <v-flex xs12 class="pt-3 text-xs-right"> <v-btn flat outline @click="validateAndDoStuff">Validate</v-btn> </v-flex> --> </v-layout> </v-form> </div> </template> Above is a simple form with two fields - user-id and email. We have specified the validation rules applicable for the fields, and we define those rules in data.
...
tldr; There is no spoon.
Longer version There is no one answer. Choose one, and get the job done.
Even longer version Javascript is versatile and blah blah. But, how should you begin your search for the right framework?
It took me no less than 3-4 weeks to get acclimatized with the nuances and settling down with a favourite framework. None should make the same mistakes. Here’s a humble-list (tm) -
...