Tuesday, March 30, 2021

Top 11 Best Practices For Vue.js Development

 

Top 11 Best Practices For Vue.js Development

Vue.js is Javascript open-source front-end building platform to design single-page application. Vue.js developers can use a single file component instance to build rich applications. You can combine the codes with Vue.js for better performance. Vue.js frameworks offers advantages over architectures such as React and Angular because of its lightweight nature and unique framework design principles. Here we’ve curated some of the evolving vue.js best practices. As Vue.js is becoming more and more favourable, these best practices will help you to develop an effortless web app.

You can also know new features and improvements in Vue.js 3.0 at- What’s New In Vuejs 3.0 ?

Top 11 Best Practices For Vue.js Development-

1. Use Data Property On Component-

This is an important Vue.js best practice. You should use data property on a component as a function that returns an object instead of data property as a simple object. When the value of data is object, it’s shared across all instances of component.

data: {
  title: ”
}

If you want to use title property from different places of component and somewhere you have changed the value of it, it will be reflected at all places of the component because you are using an object and each instance of component references the same data object, changing the title from one portion will also change the title of every other portion. 

Use data property as a function so that each part of component gets a different instance of data property.

data: function () {
  return {
  title: ”
 }
}

2. Use Kebab-Case-

You must always try to use kebab-case while writing any custom event name as event names are automatically changed to kebab-case internally if we don’t provide it in kebab-case. Let us see an example of data sharing between parent & child component:

Child:
<button v-on:click=“$emit(‘increase-count’, 1)”>
 Increment
</button>
Parent html:
<counter
 …
 v-on:increase-count=“increaseCounter”
></counter>
Parent js:
methods: {
 increaseCounter: function (count) {
  this.value += count
 }
}

3. Keep npm Packages Updated-

  • According to the Vue Style guide base components can only contain HTML elements, 3rd party UI components and other some additional based components. 
  • Update npm packages on regular basis to avoid any dependency errors and to use the latest/updated features provided by individual packages.
  • For example, if you have configured vuetify the design patterns in the VueJS project, vuetify regularly updates its packages to provide the best UI with some breaking changes. Hence it is better to update NPN packages regularly to avoid bulky or breaking changes.

npm outdated // run to check outdated npm packages

npx npm-check-updates -u // run to check updates outdated npm packages

npm install // run to update npm packages

4. Manage Global File For Shared Variable –

To make the system more generic and easy to update, manage global configurations(i.e. API URLs. Third party URLs if any, keys can be used in any integrated tool, theme settings) or in a separate file (i.e environment.json). It will help your website to update any global configurations without any re-deployments. 

5. Rule For Directive-

Use key attribute with v-for directive. This attribute is used to check the uniqueness of every list item. Vue’s virtual DOM creates VNodes on every items of a list. Hence if there is no key attribute in the list items then virtual DOM will not identify every item separately. Thus, it will be difficult for the virtual DOM to detect changes for specific list item.

<div v-for=“item in items” :key=“item.id”>
 {{ item.value }}
</div>

6. Rule For V-

You should not use v-if with v-for because v-for has higher priority than v-if. Let us see an example-

<ul>
  <li
 v-for=“car in cars”
 v-if=“car.isActive”
 :key=“car.id”
 >
 {{ car.model }}
  </li>
</ul>

Here, the loop will be iterated over all the items in the list and then it will check the v-if condition. Hence this is not a good practice. Rather than this, we can compute the list before rendering so that just active cars will be there to iterate.

<ul>
  <li
 v-for=“car in activeCars”
 v-if=“car.isActive”
 :key=“car.id”
 >
 {{ car.model }}
  </li>
</ul>
 
computed: {
  activeCars: function () {
  return this.cars.filter(function (car) {
  return car.isActive
 })
 }
}

7. Use Of Component Properties-

It is good to use computed properties instead of using method invocation for any data changes. Computed properties are cached according to their dependencies. A computed property will just re-evaluate when some of its dependencies have changed. In comparison, method invocation will always run the function when a re-render happens.

Using computed:

var vm = new Vue({
 el: ‘#example’,
 data: {
 firstName: “John”,
 lastName:”Doe”
 },
 computed: {
 setFullName: function () {
 return this.firstName + ‘  ‘ + this.lastName
 }
 }
})

Using methods:

methods: {
 setFullName: function () {
 return  this.firstName + ‘  ‘ + this.lastName
 }
}

8. Used Suitable Data Type Assign For Variable-

  • Use proper data types rather than “any” to minimize the casting time and other casting errors. 
  • Avoid casting inside the loops.
  • For the two data types assigned to the same property, implement type casting by using both the types and conditions.

Example:

 
// Wrong
const age: any = 0; [hard to identify response type at the places this variable used and also hard to track errors on assignments]
 
// Right
const age: number = 0; [easy to track and identify response type]

9. Data Should Always Return Function-

When you declare a Vue component data, that aspect of data should return a value. With other cases, when it does not return an output, that data information will be shared at all instances of component value.

Example:

As per the example below, the functional data is not returning any output. Hence, you cannot access properties outside the data function. It will generate runtime error.

data: {
value: "Vue.js Application",
itemList: [],
counter: 0
 },

Right Way:

data: function () {
return {
value: "Vue.js Application",
itemList: [],
counter: 0
};
  },

10. Clean Code And Refactoring-

  • Use shared/separate file for static functions/properties for reusability. It will help to keep a shared/static code at the same file in entire solution.
  • Make use of tslint or eslint tools for maintaining the code quality
  • In vue, you can decrease the line of code by narrowing the UI into smaller components.
  • Use keywords (Const/Let) provided by typescript smartly rather than var keyword of Javascript.

Example:

Bad Practice:

Var test: number = 0;

“Identifier ‘test’ is never reassigned; use ‘const’ rather than ‘var’

You will get the error as mentioned above if tslint is configured properly when you run the project

Good Practice:

const test: number = 0; // if static, use const
let test: number = 0; // if updateable, use let

11. Use Of Shorthands-

You should always use shorthands for directives or we should never use it. Means you should not mix of using shorthands and full name of the directives. 

Directive shorthands (: for v-bind:, @ for v-on: and # for v-slot) should be used always or never.

Final Words-

These are some of the best practices for vue.js development. There can be some others too. You can build effective applications by using these best practices. If you are facing any difficulties while using vue.js for development, consult with Solace experts. We are here to help you through consultation and development. You can also hire vue.js developers of solace team for successful development of applications. Connect with Solace and get a free quote for development. We will be happy to help you.


Saturday, March 27, 2021

Ruby Vs Java- A Detailed Comparison

 


Whenever you are going to build a website or web app, you should consider various issues like hiring a software development company, defining project goals, and preparing software requirement documents. Apart from this, another important question is to choose the right technology stack. Ruby and Java both are popular languages to build web solutions. But which one to choose for enterprise web application development is a big question? So, here comparing Ruby vs Java, we find differences between these coding languages to make the right choice. Here, we will cover the decision -making factors that help you to make the right choice for your app development in 2021. But before digging into the comparison, let us see the overview of Ruby and Java.

Ruby-

Programming language Ruby is an interpreted server-side scripting language. It is much more flexible and dynamic, and allows programming constructs like reflection, dynamic typing or dynamic scoping. There is no need of compilation process and Ruby code is not executed directly by the processor but by a so-called interpreter. This reads the script code and converts it at runtime into processor executable code. So, in order to run Ruby scripts, an appropriate interpreter must be present on the executing machine. Ruby interpreters are available for today’s popular platforms Windows, Mac OS X, and Linux. 

Key Features-

  • Open-source
  • Multi-platform
  • Interpreted language
  • High scalability
  • Dynamic + duck typing
  • Has smart garbage collector
  • Can embed Ruby into HTML
  • Applicable to write CGIs, build web and intranet applications
  • Support of various GUI tools including OpenGL, Tcl/Tk and GTK
  • Support of Sybase, Oracle, MySQL and DB2 connection

Java-

Java is a programming language based on C and C++ syntax. It doesn’t have pointers and so programmers cannot accidentally access the wrong memory address. Java is highly valued as an object-oriented, secure, easy-to-learn and computer-language independent programming language. Various sophisticated features like exception handling, concurrency and graphical user interface have been integrated into Java programming language. Java apps run under Windows and MacOS, various Linux and Unix derivatives, and even in web browser- and on different processor substructures x86, ARM or PowerPC. 

Key Features-

  • Object-oriented language
  • Open-source
  • Compiled and interpreted language
  • Static typing
  • Built-in security
  • Simple memory management model
  • Platform independence
  • Multithreading capabilities
  • Automatic garbage collection
  • Dynamic compilation and dynamic class loading

Ruby Vs Java- A Comparison

1. Language Maturity-

Ruby-

It is a general purpose programming language having first stable version released 1.0 in December 2005. Latest version of Ruby 6.1 was out in December 2020 and the community is waiting for the to be released TBA version 7. According to history, the Ruby community is strong and has a great scope in the future. One can surely rely on the rails framework or enterprise app development.

Java-

First stable Java version JDK 1.0.2 was released in 1996. Thereafter, successfully Java standards editions 6, 7, 8, 9 and 10 was released in 2006, 2011, 2014, 2017 and 2018. Later on, stable versions 12, 13, 14 and 15 were released last in September 2020. From the above efficient history of Java, we can understand the vast community, maturity, stability and scalability of Java programming language.

2. Architecture-

Ruby App Architecture-

MVC-

Ruby follows the convention over configuration COC strictly and implements MVC(model view controller) architecture to ease the maintenance of RoR application. One of the biggest advantage of using MVC architecture is that you can keep the business logic and display of your application separate an so your app doesn’t affect when something goes wrong. This keeps the model(database), view(frontend) and controller(business logic) separate. 

Model-

In ruby app, models consist of database information which allow validation and helps them to communicate amongst themselves.

View-

View, frontend of R app includes HTML pages and some other formats like PDF, RSS, XML etc.

Controller-

It interlinks the model with view- logic of application. Controller processes the browser requests and sends the result to the view.

Java App Architecture-

Java programming architecture will help you to understand the execution and implementation of Java code. There are two consecutive processes- compiling and interpretation. Let us see, how java program file runs.

  • Code that you write first goes to the Java compiler
  • Compiler converts source code to byte code
  • Then, this byte code moves to the java virtual machine
  • JVM converts byte code into machine code and your java program is executed

3. Development Environment-

Though Java is compiled, turn-around times are short. This is due to current development environments such as Eclipse that use an incremental compiler. Java programmers have access to tools which override various language specifics. 

Among Ruby programmers, it is still widely used to depend on vim or emacs for lack of mature development environments. Also, the main commercial development environments are already appearing and both blend into Eclipse and the Free RIDE written in FXRuby will be further developed.

4. Deployment-

In J2EE environment, many XML files are typical to edit. Also special archive files (Jar, Ear, War, etc) must be generated. This can be done through plugins integrated into the development environment, or you can use a deploy tool from an app service provider. For small apps, it is sufficient to master Ant. Webstart addresses the subject of updates.

With Ruby, RubyGems develops to the deployment standard. Also, the web framework Ruby or continuous integration server Damage control comes as Gems. There are usual, platform-dependent delivery strategies in both Java and Ruby like Windows installer or Debian packages.

5. Typing-

Know more at - https://solaceinfotech.com/blog/ruby-vs-java-a-detailed-comparison/

Thursday, March 25, 2021

Top 7 Micro Front-end Frameworks That You Should Know

 


The idea of micro front-ends is to break down the frontend monolith into smaller, manageable parts. Every team can own its features end-to-end, work in their codebase, independently release versions, continuously deliver small incremental upgrades, and also integrate with other teams through APIs so that they can compose and manage pages and apps together. There are lots of approaches to micro front-ends, from smart build-time integrations of components to run-time integrations using custom routers. Here we have curated some of the best tools to build micro frontends. Before digging into the micro front end frameworks, let us see, what is micro front-end?

What Is Micro Front-end?

Micro front-end means approaching front-end development process of web apps with concept of microservices. Till now, the prevalent practice was to use microservices architecture as a foundation on which feature-rich apps can be built. So, the applications developed were called as frontend monolith. Disadvantage of this approach was that the architecture became a part of the app over time. It is developed separately, so maintenance is a challenge.

Micro front-end solves this issue. It’s approach is based in the concept that a web application is a compilation of independent features which can be developed by various teams and them combined to create a homogenous interface. Micro front-end architecture provides a cross-functional approach where various teams with different specializations develop end-to-end features from database to user interface. The subsequent app is less massive and more friendly. 

The app is split according to the business domains across the stack. So developers can avail the same velocity and flexibility as backend teams have while working with Microservices architecture. Let us see top 7 micro frontend frameworks.

Top 7 Micro Front-end Frameworks-

1. Module Federation-

It is a Javascript architecture which allows you to develop multiple separate builds without any codependency. Together they form a single application like, piece of jigsaw.

This tool benefits the runtime approach and allows Javascript to dynamically import code from other apps. This prompts the creation of Javascript entry file which is available for download to other apps though webpack configuration. Module federation is most effective tools for countering the code dependency problem and so enables bundle size expansion through dependency sharing.

2. Bit-

Bit CLI is a popular tool for component-driven development. With Bit, you can build, integrate and compose independent components together. It lets developers efficiently compose frontends in build-time to enjoy best of safety and robustness of “traditional monoliths” and the simplicity and scalability of micro frontends.

By using Bit, different teams can build, publish and expose their components independently, while working together with different teams to turn the web development process into modular composition of features and components. Also, to OSS tools for components-driven development, Bit provides a cloud platforms for teams to build changes and collaborate on components together so that development can be managed efficiently and scaled while keeping all teams completely independent to deliver autonomously.

Bit also provides a unique CI/CD process to ensure each frontend gets its own independent and fast process, means different teams can integrate changes safely without having to wait, or break anything. Programmers can continuously and safely propagate changes to components across all impacted apps. Subsequently, workflow is improved with simple decoupled codebases, autonomous teams, small well defined APIs, independent release pipelines and constant incremental upgrades.

3. Single SPA-

It defined itself as a “Javascript framework for frontend microservices”. In sort, it applies a lifecycle to each application. Every app can respond to url routing events and should know how to bootstrap, mount and unmount itself from the DOM. Difference between traditional SPA and single-spa apps is- they should be able to coexist with different applications, and they don’t each have their own HTML page. Hence if you’re looking to put together various frontends or frameworks into one DOM and aim to integrate at runtime, must give Single SPA some serious consideration.

Popular applications like- Gmail, Google Maps, grammarly are deploying the single SPA framework. While using Single SPA, the template and sub-application should know the location in the target namespaces of frameworks lifecycle function. This is called as contract between a container and sub-application.

Webpack can be used to uphold the target location. For this, two new entries have to be added to the module.exports.output in each sub-application’s Webpack configuration. Now, you are ready to configure the main app. You render it and afterward add DOM placeholders for each sub-application. After this, the Single SPA library is included to the package.json file. This prepares the sub-application to be registered in the Single SPA library. After this, the runScript sources the external JS script file, which is run by adding new script to the document.

4. Qiankun-

Qiankun is a tool for Micro Front-end implementation based on Single SPA but one that has been made production-ready. It tries to address main challenges that developers face when making an application by using smaller independent applications. Addressing the issues of component integration and publishing static resources, it guarantees that these sub-applications remain independent during the whole process, development to deployment. This isolation proves importance in issue handling of public dependencies and performance.

5. Podium-

This is a tool for ‘server-side composition of Micro Frontends’ and helps teams to develop and serve various components of web app in isolation, treating every part as a complete app on its own. Those isolated parts called as Podlets and can be developed with node.js Podium library or any tech stack of developer’s choice. This framework works on the process of developing different parts of whole application in isolation, giving greater flexibility to your development teams.

6. Mosaic 9-

It is a set of services, libraries together with a specification which defines how its components interact with each other, to support a microservice style architecture for large scale websites. Mosaic make use of Fragments which are served by separate services and are composed together at runtime as per template definitions. This is composed with a bunch of packages which includes handling routing, layout, template storage and showing UIs.

7. Luigi-

This is a micro frontend JavaScript framework lets you to create an administrative UI driven by local and distributive views. It allows a web app to communicate with micro frontends which the app contains. To ensure smooth communication, one can configure settings like navigation, routing, authorization and UX elements. It consists of Luigi Core app and Luigi client libraries. They set up secure communication between the core application and the micro frontend using postMessage API. 


Wednesday, March 24, 2021

Top 10 Common Mistakes In Go Programming

 


Go is a popular and  trendy programming language. But Go developers often face particular common bugs and errors. Developers address them as Gotchas. Golang is a comparatively new programming language by Google. Native gophers often face these pitfalls, so here we came with some common mistakes and its solutions. Checkout the following Gotchas and if you have already come across them in Go programming journey, know the solutions of it.

Top 10 Common Mistakes In Go Programming-

1. Multiple-value in single-value context-

Issue-

 t  := time.Parse(time.RFC3339, “2018-04-06T10:49:05Z”)
fmt.Println(t)
../main.go:9:17: multiple-value time.Parse() in single-value context

When you try to parse the date and time, you get a compiler error.

Solution-

 t, err := time.Parse.RFC3339, “2018-04-06T10:49:05Z”)
  if err != nil {
      // TODO: Handle error.
}
fmt.Println(t)
2018-04-06 10:49:05 +0000 UTC

The parse function with time returns a time value and error value, and explicitly you need to use them. Or To ignore the unwanted error values, you can use a blank identifier _as below:

 m := map[string]float64{“pi”: 3.1416}
_, exists := m[“pi”] // exists == true

2. Possibly undesired value being used in goroutine-

Range variables in a loop are reused at each iteration; so, a goroutine created in a loop will point to the range variable from upper scope. In this way, the goroutine could use the variable with an undesired value. As per the below example, value of index and value used in goroutine are from the outer scope because goroutines run asynchronously, the value of index and value could be (and usually are) different from the intended value.

mySlice := []string{"A", "B", "C"}
for index, value := range mySlice {
go func() {
fmt.Printf("Index: %d\n", index)
fmt.Printf("Value: %s\n", value)
}()
}

To overcome this problem, a local scope should be created, like in the example below.

mySlice := []string{"A", "B", "C"}
for index, value := range mySlice {
  index := index
 
   value := value
go func() {
fmt.Printf("Index: %d\n", index)
fmt.Printf("Value: %s\n", value)
}()
}

Another approach to deal with this could be by passing the values as args to the goroutines.

mySlice := []string{"A", "B", "C"}
for index, value := range mySlice {
go func(index int, value string) {
fmt.Printf("Index: %d\n", index)
fmt.Printf("Value: %s\n", value)
}(index, value)
}

3. Nil pointer dereference-

Most of the time Go-developers face the issue of dereferencing of a nil pointer. Let’s check the issue-

 type Point struct {
     X, Y float64
}
Func (p *Point) Abs() float64 {
         Return math.Sqrt(p.X*p.X + p.Y*p.Y)
}
 func  main() {
            var p *Point
           fmt.Println(p.Abs())
}
Panic: runtime error: invalid memory address or nil dereference [signal] SIGSEGV: segmentation violation code=0xffffffff addr=0x0 pc=0xd2c5a]
 
goroutine 1 [running]:
main.(*Point).Abs(...)
         ../main.go:6
main.main()
        ../main.go:11 +0x1a 

Pointer in the main function (p) is nil, so you can not follow the nil pointer as it causes run-time error.

Solution-

func main() {
         var p *Point = new(Point)
         fmt.Println(p.Abs())
}

Either you can create a new Pont as mentioned in above snippet. Or Methods with pointer receivers either need a value or a pointer, so try this-

func main() {
var p Point //has zero value Point{X.0, Y.0}
fmt.Println(p.Abs())
}

4. Regular expression mismatch-

Know more at- https://solaceinfotech.com/blog/top-10-common-mistakes-in-go-programming/

Tuesday, March 23, 2021

What’s New In Vuejs 3.0 ?


Vue is a progressively Javascript Framework to build UI and single page apps. It is an open-source Model-View-View Model (MVVM) framework. The core framework is basically focused on the view layer and it can be easily integrated with other libraries and projects too. Using modern tools and libraries, Single page apps can be easily handled. Vuejs 3.0 has been officially launched and planned to upgrade to Javascript framework which is used to build web user interfaces. Vuejs 3.0 is smaller, faster, more maintainable, equipped with better TypeScript support, and easier to target native. Let us see what’s new in Vuejs 3.0?

What’s New In Vuejs 3.0?

In the last few years, there has been changes in vuejs development. Also, the community has grown from a small upstart to a full-fledged SPA library. With this new version, the team has added few supports to augment the library, simplify coding on Vue and adopt modern techniques of web development. Let’s have a look at new features of Vuejs 3.0.

Features Of Vuejs 3.0-

1. Composition API-

It is one of the greatest features in Vuejs 3.0. It has added a set of function-based APIs called as Composition API. These APIs are added to address the issues in Vue 2. Composition API has was launched as a plugin however in Vuejs 3.0 it doesn’t have to be installed like a plug in like previous. Now, it is in-built into the package and can be used without any extra setup. One main reason of formulating Composition API is to improve quality of code by allowing decouple features of logic.

In vue 2 where developers depends on extending the object and then share logic, vue 3 enables the sharing feature through standard Javascript/Typescript patterns rather than inventing new. It helps to see the features as they were added. Also, the Composition API makes it easy for types to infer, which supports the typescript in a better way. Vue 3.0 allows the component building and new API toco-exist with options API, without replacing it. Composition API provides flexible code organization and logic reuse capabilities with other improvements. Codes are easy to ready and organized better when written with Composition API.

2. Multiple Root Elements(template syntax)-

In Vue 2, template tag can only take one root element. Though we had just two <p> tags, we had to enclose them within a <div> tag to work it. So, we had to change the CSS code and in the parent component so as to looked as expected. In Vue 3, this restriction is removed. Now, there is need for a root element. You can use any number of tags directly inside the <template></template> section:

<template>
  <p> Count: {{ count }} </p>
  <button @click="increment"> Increment </button>
  <button @click="decrement"> Decrement</button>
</template>

Equivalent code in Vue 2:

<template>
  <div class="counter">
    <p> Count: {{ count }} </p>
    <button @click="increment"> Increment </button>
    <button @click="decrement"> Decrement</button>
  </div>
</template>

3. Better Typescript Support-

With the new Composition API, the internal functions are used as expected in JavaScript which takes into consideration much better TypeScript support. This results in better type inference with bindings returned from setup with props declaration used to infer types. TypeScript definitions benefit JavaScript users largely, making the Component code by TypeScript and Javascript look identical. The typescript helps in upgrading the maintainability of the Vue codebase and makes it simpler for developers to contribute. It is a frequent choice for large projects due to its popularity. Vuejs 3 internals in TypeScript assists to benefit completely from Vue’s TypeScript with the standard code support available in modern IDEs like Visual Studio Code or WebStorm. Since TypeScript’s Vue code is 90% Javascript, javascript users benefit from code intelligence features with modern IDEs. 

4. Reactivity-

Vue 2 had great reactivity but there were some cases where Vue 2 fell short. Let’s revisit Vue 2 and see what those limitations were-

To show reactivity, we’ll use watchers to listen to one of the state variables and then change it to check whether the watchers are triggered: 

<template>
  <div class="hello" @click="test">test {{list }} {{ myObj }}</div>
</template>
<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      list: [1, 2],
      myObj: { name: "John" }
    };
  },
  watch: {
    list: {
      handler: () => {
        console.log("watcher triggered");
      },
      deep: true
    }
  },
  methods: {
    test() {
      this.list[2] = 4;
      this.myObj.last = "HS";
      delete this.myObj.name;
    }
  }
};
</script>

None of the above three modifications —, for example, adding new item to an array based on the index, adding new item to an object, or removing an item from the object — is reactive in Vue-2. So, watchers won’t be triggered, or the DOM would be updated. We had to use the vue.set() or vue.delete() methods. In vue 3, these work directly without any helper functions:

export default {
  setup() {
    let list = ref([1, 2])
    let a = ref(0)
    let myObj = ref({ name: 'John' })
    function myFun() {
      list.value[3] = 3
      myObj.value.last = 'HS'
      delete myObj.value.name
    }
    return { myFun, list, myObj }
  }
}

We can see that watcher was triggered all four times in the Vue 3 setup.

5. Global Mounting-

When you open main.js in the about project, you can see that something is different. No longer we use the Global Vue instance to install plugins and other libraries. Rather, you can see createApp method:

import { createApp } from 'vue'
import App from './App.vue'
const myApp = createApp(App)
myApp.use(/* plugin name */)
myApp.use(/* plugin name */)
myApp.use(/* plugin name */)
myApp.mount('#app')

Benefit of this feature is that it protects the Vue app from third-party libraries/plugins we use that might override or make changes to the global instance- mostly by the use of Mixins. 

Now, with createApp method, we install those plugins on a specific instance and not the global object.

6. Portals-

This is a feature where we can render a part of code which is present in one component into another component in a different DOM tree. There was a third-party plugin called portal-vue that achieved this in Vue 2.

With Vuejs 3.0, portal is inbuilt and also it is easy to use. Vuejs 3.0 has a special tag called <Teleport> , and any code enclosed within this tag will be ready to teleported anywhere. The Teleport tag takes a to argument.

<Teleport to="#modal-layer">
  <div class="modal">
      hello
  </div>
</Teleport>

Any code inside <Portal></Portal> will be displayed in the target location mentioned.

<div id="modal-target"></div>

7. Multiple v-modes-

V-mode is a directive which is used for two-way binding on given component. Mostly it is used with form elements and custom components.

V- model from the form elements looks like-

<input v-model="property />

It can be modified from the inside of component by passing reactive property and listening  to input events. 

Let’s rewrite the above example to see how the syntax will affect-

<input
  v-bind:value="property"
 v-on:input="property = $event.target.value"
/>

V-model directive can help in syntactic sugar for two-way binding in our components. But you have only one v-model per component. This is the best feature of Vuejs 3.0 and it lets you to give v-model properties names without any restriction.

8. Suspense-

This feature helps in rendering a default component untill the main component fetches the data. The asynch operations which are used to fetch data from server are done by Suspense. It can be used in individual parts of template or complete template. This concept derived and adapted from the React ecosystem to suspend your component rendering.

Wrap up-

With the development of the Vue, the community has led to the enhancement of the framework. These are some of the impressive features of Vuejs 3.0. There can be few others too. If you are thinking to use Vue for your next project, know these amazing new features in Vue. In case of any difficulties regarding vue development, consult with Solace experts. We are here to help you through consultation and development with new features. You can also hire skilled Vue developers of Solace team on flexible basis. Connect with Solace and get a free quote for an effective vue development. We will be happy to help you.