Vue 3 Composition API provides a new approach to organizing data models and functions. Previous options of API don’t provide features to organize models or business logic in a logical manner. Composition API provides a great feature to organize codes, in a more reusable manner and it improves the readability of big components.
Option API distributes codes among data block, computed blocks methods, and watch functions. Code has been spread in all the places there is no logical fragmentation. That structure is what makes it difficult to understand and maintain a complex component.
However, when we are working with bigger code blocks it’s convenient to fragment code blocks based on logical concerns. It would be much nicer if we could collocate code related to the same logical concern. And this is exactly what the Composition API enables us to do.
If you have experience with Vue Js 2, you must have seen the Option API, where the codes aren’t fragmented in a logical manner based on its functionality. A component might look like this. If we apply different color codes for code fragments according to the Vue Composition API RFC showing how code fragments will be.
Here, the goal is to fragment codes based on their feature / logical functionality. Using Composition API, we can extract this logic and place it in separate files. And we can consume those inside the Setup method in Composition API. The separation of options obscures the underlying logical concerns. In addition, when working on a single logical concern, we have to constantly “jump” around option blocks for the relevant code
Nuxt Js provide Composition function using Nuxt Composition API. @nuxtjs/composition-api module that brings first-class Composition API support to Nuxt. The @nuxtjs/composition-api package is a wrapper over a @vue/composition-api plugin which means that along with Nuxt-specific utilities it contains all “standard” Composition API functions like ref or computed.
Before starting the feature of the Composition, first, we will look into how Nuxt Composition API addons facilities to us to work with Composition in Nuxt Project. To enable Composition in Nuxt project we have to setup NuxtJs Composition API.
The installation is straightforward, just like with every other Nuxt module. First, we have to install the package:
npm install @nuxtjs/composition-api –save
And register the module in our nuxt.config.js
{ buildModules: ['@nuxtjs/composition-api' ] }
The module is registering @vue/composition-api plugin under the hood so we can immediately use its features in our project without any additional code.
The @nuxtjs/composition-api provide SSR capabilities within Composition.
UseFetch which is a Composition API wrapper for a well-known Nuxt fetch that is commonly used to fetch asynchronous data (both on a server and client-side)
It does two things:
It makes sure that the asynchronous function that passed as its argument resolved. Then the result conveyed to the client-side through the window. NUXT object and picked up by your client-side code as its initial state.
It prevents the client-side execution if navigation has been made on a server-side. Because of that, we are not performing unnecessary network calls if we already have the data from the server-side fetch.
To make use of useFetch in our composable we just need to wrap it around our asynchronous code:
Among data-related server capabilities, Nuxt composition API is delivering a set of composable to interact with other composable APIs. One of the most helpful features is the use of Context. As represented in the name, it facilitates us to access Nuxt context inside our composable. We can use this instance to access router, store, and properties via Nuxt Modules.
In Vue 3 Composition, Vue Context is accessible inside the Setup() method only. It’s not allowed to accessed outside. Therefore, if we want to access the Context in different Compose files, we have to pass context as a parameter to the specific file. With the help of the use Context () method we can access Context Object inside any Composition API.
Let’s see how we can organize our component by feature and reuse our code across other components. In this below example it’s a Student Portal that has three main feature areas; those are Course Enrolment, Showing Progress Report, Showing Student Profile. If we see the functionality of the student portal, we can clearly identify that it has three modules as follows.
Let’s see how we can organize the code using Composition API.
Here Enrollment, Progress Report, and Student Profile moved to different files. Its related fields and methods are also placed in the same file. Therefore, it’s more human-readable and meantime maintainable. And we can use the above compose section anywhere in our application as used on this page.
There are two approaches available to build reusable components in the Vue application. Both have their strength and weakness. Those are using Property and using Slot. We have to select the correct approach based on the needs.
For example, there is an Address Component that used to capture the address of the student. The same component has been used to capture local addresses and foreign addresses as well. So based on the country, the address fields should changed. This has been achieved using Props for the component. The component has multiple props to change the behaviour of the component.
This approach is suitable for small components. If the number of props increases, it’s difficult to manage the component because we are introducing logic inside the component to maintain the state. It’s difficult to understand.
To handle this scenario with Vue 2.6 Slot directive has been introduced. Through this, we can distribute the content to the component. So rather than keeping the HTML content in a component and changing the behaviour based on the props. We can set the HTML content to the component from the outside.
So, we understand the whole concept from the definition of slots it’s about making components reusable. Now, we’re going to dive in with some examples showcasing Vue slots and talk about how to make use of them.
We will take the same example and see how we can use Slot instead of Props.
You can notice in the above picture that we have removed Drop down and Input Control and we have placed <slot> tag. This is going to work as a placeholder and when we are using this component we have to define the HTML Content for this Slot as given below.
Through this, we can distribute the content to outside of the component. Therefore, we are able to control the component behaviour from the outside.
We have seen how we can use Nuxt Composition API to fragment code in a logical manner and how we can reuse them among the components. Meantime we can create reusable UI Components using Slot directives. The goal of the Composition API is to increase readability and facilitate us to create components in a more reusable manner.
Authored by Deepakumar Ganeshamany @ BISTEC Global
Source Code: https://github.com/bistecglobal/VueCompositionAndComponents
In today’s fast-paced tech landscape, staying ahead of the curve means agility and efficiency. But with limited resources and talent pools, how can companies ensure they’re delivering innovative software solutions at breakneck speed? The answer lies in embracing a powerful strategy: building an extended development team.
While you might have an amazing in-house team, tapping into a pool of specialized remote talent can unlock a treasure trove of benefits. Forget the limitations of traditional outsourcing extended teams offer a collaborative, cost-effective, and time-saving approach to achieving your software development goals.
So, let’s dive into the top 5 reasons why building an extended development team is a game-changer for your business:
Streamlined Recruitment, Rapid Deployment
Cost-Effectiveness without Compromising Quality
Enhanced Transparency, Trust, and Collaboration
Forget the tedious recruitment process and lengthy onboarding cycles. Extended teams offer a rapid deployment solution, allowing you to assemble a dedicated team and hit the ground running in no time. Plus, you stay in complete control, as project management remains firmly in-house.
Let’s face it, budget matters. Extended teams offer significant cost savings compared to traditional hiring. Imagine cutting your development costs by 15-40% without sacrificing quality. This efficiency comes from leveraging nearshore or offshore talent pools where salaries are often lower, but the skillset remains exceptional. Remember, cost-effectiveness doesn’t translate to compromise – you get access to a global pool of vetted developers with proven track records, delivering exceptional results without breaking the bank.
Collaboration is the cornerstone of success, and extended teams foster an environment where transparency and trust reign supreme. Your in-house and remote teams work side-by-side, sharing knowledge, ideas, and responsibilities. This fosters open communication, clear project visibility, and a shared sense of ownership. The result? Increased productivity, enhanced problem-solving, and a learning environment where everyone benefits.
Ditch the setup headaches. Staff augmentation requires minimal operational hassle. Say goodbye to managing payroll, employee benefits, office space, and tech support. We handle that for you, freeing you to focus on what you do best – building amazing software. You simply provide the remote team with access to the tools and information they need, and watch the magic unfold.
Speed is crucial in today’s competitive market. Extended teams accelerate your time to market by adding more hands to the development deck. With additional resources working simultaneously, tasks get distributed and completed faster. But that’s not all – dedicated remote teams laser-focus on your project, eliminating the distractions of juggling multiple assignments. This translates to faster development cycles, quicker product launches, and a competitive edge in the market.
Building an extended development team is not just about filling skill gaps; it’s about unlocking a strategic advantage. It’s about injecting your project with a dose of agility, cost-efficiency, and collaborative spirit.
The concept of ETM is a strategic advantage that has been lost in the chaos of offshoring. The concept of offshoring started in India more than 3 decades ago and already spread across many countries across the globe.
So what is ETM and why it is different?
I cite this article in Forbes talking about this concept without the branding in 2010. Now it is reality!
Imagine the team in your head office, spread throughout the globe. This gives the ability to extend your team to reach the human talent that is not available locally, but you can find through a partner like BistecGlobal.
Having a remote team in an offshore context can be a strain on you mainly because of the lack of transparency.
Most often offshore providers use the team on multiple projects and you may find yourself working with different people than who were initially assigned to you just when you were just getting started.
ETM takes the best offshoring minus the bad experience. It gives you the control you need while you retain better financial and logistical benefits. It provides you total integration with the remote teams and also with your business.
With ETM you are able to synchronize all of your “well-tuned” processors, practices and values, into your Extended Team making it a fully functional branch office with a similar design and identity.
“At Bistec Global, we’ve had different experiences working with a verity of engagement models, including ETM and we thrive in this particular environment, and here’s why”
You have the flexibility where you can apply any time or task-driven mechanism/tool to your extended team. Thereby measuring performance with 100% transparency and synchronization.
You might have a successful project that your in-house team is working on and you plan on them continuing to complete it. You can delegate all the new projects to your extended team.
Or you can focus on moving some of the work your home team is doing to the ETM while the home team takes on high-value customer-centric work.
Not being tied down to a single location is a great thing. By using the ETM you can have a team in another location of the world, with a wider knowledge base of technologies, local markets, and other skills that your business can benefit from.
Having different kinds of people working globally, using their knowledge, will lead to creating a startup environment that can take a solution or application on a global market easier than having a centralized local team.
An extended offshore team can save time and money and yet give the expertise that you need to make your application or solution work.
The extended team is involved in the complete cycle of a job/project, not just an isolated part of it which makes for better transition and continuity.
Your corporate image should reflect through all your products and service. This can only be achieved by extensive and continuous team training throughout the company and your extended team…
An extended team is part of a bigger team and employees associate better with their job roles with larger companies which reduces the effect on turnover and dependencies.
By doing so, leads to a steady workflow and becomes resilient to changes in the cooperates which otherwise would be difficult to manage.
A global team means that you can easily have a presence in more than one market. Of course, in today’s world, you can have global reach just by having a great solution and also great marketing, but having people in different parts of the world, that knows the local market and the local mentality can indeed help you build a market reach faster.
Your business generally requires extended hours of work which can result in overworked and demotivated employees. Moreover, the overlap of work hours with your extended teams is likewise important and the part that does not overlap will work to your advantage when planning your project delivery, especially at peak times.
The use of a global talent pool has gained popularity over the last decade. The Extended Team Model is the next stage of outsourcing. Affiliation of your business rather than a group of contractors. ETM offers more flexibility and a new level of dedication. Your extended team may extend according to the objectives set and the resources you require while maintaining your core values and identity.