
VueJS doesn't have to be a Single-Page Application
What is VueJS?
VueJS is a progressive JavaScript framework that is incredibly adaptable. It is often brought up along with other popular JavaScript frameworks and libraries such as ReactJS and Angular. It was made by Evan You (also the founder of Vite which is a widely used frontend build tool) and has a large ecosystem of libraries and frameworks that are widely used throughout VueJS applications and pages. VueJS is often compared against ReactJS as they look and function somewhat similarly with a few differences.
The Goal of this Article
Often times Vue is known to be a Single-Page Application, and while it definitely can and it does a great job doing so, I would like to show an alternative way of utilizing Vue. Instead of using full Single-Page Application architecture, Vue can be used to easily plug and play into existing pages and applications with relative ease without the requirement of having a full SPA with routing, state management and all of the other complexities that come with a Single-Page Applications.
This article will not be an in depth guide on how to use Vue (though we will touch a few introductory level concepts). In this article, I will be using raw HTML pages as well as a .NET application with Razor pages to show how we can implement Vue into certain pages, however these same principles and ideas can be utilized across various scenarios. For the examples that will be shown in this post we will be using the modern Vue3 version, however the older Vue2 version may also be used.
Why Would I Not Just Use a Single-Page Application?
Vue does a great job of being a Single-Page Application but there are a few reasons why you may want to go this route rather than building an entire SPA:
- Adoption With Legacy Codebases
- Often times as developers we have a pre-existing codebase we need to work with. Lets say that we have a 10 year old .NET MVC Application and we want to add modern Vue functionality to it. To do this would potentially cost months of development time rewriting the entire codebase.
- Often times as developers we have a pre-existing codebase we need to work with. Lets say that we have a 10 year old .NET MVC Application and we want to add modern Vue functionality to it. To do this would potentially cost months of development time rewriting the entire codebase.
- Reduced Complexity
- SPAs introduce overhead that may not be justified for your specific use case:
- SPA Routing - Separate frontend routing
- Build Tooling - Managing the full frontend ecosystem
- API Design - Full API interface is needed for all data
- State Management - For complex state management, some form of state management tooling is needed to track state across various pages (VueX, Pinia)
- SPA Routing - Separate frontend routing
- SPAs introduce overhead that may not be justified for your specific use case:
- Simplifying Deployments
- Keeping Vue as a non-SPA integration means there are no changes needed for deployment pipelines
- Keeping Vue as a non-SPA integration means there are no changes needed for deployment pipelines
- Gradual Adoption Process
- Adding Vue to individual pages can allow for a team to get familiar with Vue and slowly start sprinkling in pieces as quickly or as slowly as they want
- Adding Vue to individual pages can allow for a team to get familiar with Vue and slowly start sprinkling in pieces as quickly or as slowly as they want
The Basics with plain HTML
Let's start with a very basic HTML page with a simple table on it:
1<body>
2 <div class="container" id="tableapp">
3 <h1>User Data Table</h1>
4 <table>
5 <thead>
6 <tr>
7 <th>ID</th>
8 <th>Name</th>
9 <th>Email</th>
10 <th>Role</th>
11 <th>Status</th>
12 </tr>
13 </thead>
14 <tbody>
15 <tr>
16 <td>1</td>
17 <td>John Doe</td>
18 <td>john.doe@example.com</td>
19 <td>Admin</td>
20 <td>Active</td>
21 </tr>
22 <tr>
23 <td>2</td>
24 <td>Jane Smith</td>
25 <td>jane.smith@example.com</td>
26 <td>User</td>
27 <td>Active</td>
28 </tr>
29 <tr>
30 <td>3</td>
31 <td>Bob Johnson</td>
32 <td>bob.johnson@example.com</td>
33 <td>User</td>
34 <td>Inactive</td>
35 </tr>
36 <tr>
37 <td>4</td>
38 <td>Alice Williams</td>
39 <td>alice.williams@example.com</td>
40 <td>Manager</td>
41 <td>Active</td>
42 </tr>
43 </tbody>
44 </table>
45 </div>
46</body>To add VueJS to this page, it's pretty simple. We need to import Vue and then mount it to an element.
- Add the script to the file
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>- Create the Vue instance and mount it to an element (ideally a root level element where you want the Vue functionality to function)
1<script>
2 const { createApp, ref } = Vue
3 createApp({
4 setup() {
5 const message = ref('Hello vue!')
6 return {
7 message
8 }
9 }
10 }).mount('#tableapp')
11</script>And just like that, we now have a Vue instance on the page.
- Then we can use that message ref and display it on our page
1<body>
2 <div class="container" id="tableapp">
3 <!-- Add message here -->
4 <div>{{ message }}</div>
5 <h1>User Data Table</h1>
6 <table>VueJS proves that modern doesn’t have to mean a full rebuild. You can start small, enhance what you already have, and evolve your app at your own pace—without the overhead of a full SPA. Whether it’s a simple component or a richer interactive experience, Vue gives you the flexibility to modernize on your terms.
Frequently Asked Questions
Latest Posts
We’ve helped our partners to digitally transform their organizations by putting people first at every turn.
.avif)























