title

Build A Chat App Using Html Css Vue Js

In this tutorial, you will build a chat app using HTML CSS Vue js. In this article, a guide to creating a simple interface for chatting with your friends is given. Vue js is a JavaScript framework that allows you to build fast and efficient single-page applications. Vue was created by Evan You in 2011, and it has become one of the most popular frameworks today. In this tutorial, you will learn how to create a chat app using Vue js with HTML CSS js, and the vuetifyjs library.

Creating the project and layout

First, you will have to create a folder for your project. Let’s call it a chat app and save it in the root of your project folder.

Next, you will add an index.html file which will be used as the template for all pages in this app. Add this file at the end of your directory (the last one). It should look like this:

“`html {

“`body {

“`div id=”chatbox” vue=true type=’container’ style=’font-weight:bold;px#f0c8d9′ font-size:1rem; color:#fff}“

Step 1. Create Vue Instance

The first step is to import Vue from ‘vue’.

You will create a new instance of the chat component by using the Vue instance you created in the previous step. You also need to create an instance of your new HtmlCssStyleSheet class so that you can configure its properties later on:

// Create an object that contains all necessary information for creating an HtmlCssStyleSheet object const styleSheets = {}; 

// Creates an object containing two properties: `from` and `to`. 

It returns this value when called with no arguments or when passed as a second argument 

const htmlcssStylesheet = new HtmlCssStyleSheet({ from: null, to: null }); 

// This function sets up default stylesheets based on whether they have been specified explicitly earlier or not (i.e., if there are no stylesheets specified then it assumes them being present). If there were any errors during execution then these would be reported here as well,

const notifyAll = function(error) { if (error instanceof Error) { throw error; } }; 

// Update your export object with new values… export default { name: “chat”, components: [], template : ` Message `

Step 2. Add an input field for the user to type their messages.

Add an input field for the user to type their messages.

Create a textarea, and add the name attribute to it. Set its value to your message:

Next, add an event listener for click events on this browser’s keyboard:$(document).on(“keydown”, function(event){});

Step 3. Create a method for sending messages

Now you need to create a method for sending messages. You can find the Axios library in the Vue project, or you can install it separately through npm:

  • Install Axios and its dependencies:

“`javascript

npm install –save axios@3.0.x

“`

  • Create sendMessage() method:

“`javascript

Vue.use(axio)

import axios from ‘axios’; 

// 1st line below imports `axios`. If you don’t have this installed, please follow step 1 above! 

var source = new Axios({ baseURL : process.env[‘SEND_MESSAGE_API_URL’] });

// 2nd line imports `source`, which is your App instance (created in Step 2). 

var message = {}; 

// 3rd line creates an empty object called `message`. 

This will be used later when rendering UI components as well as being passed as input values during AJAX requests made by other scripts such as Vue Router! mutateData(newData); 

sendMessage(); 

return promise; 

// 4th line makes sure you return something from your callback function after making calls into external APIs using promises

Step 4. Receive messages from your friends

Now that you have the app up and it’s running, let’s make it more interactive.

  • Receive messages from your friends:

You can now receive messages from your friends by pressing on their name in the chat list. You can also send them a message by typing it in there too!

Step 5. Add support for multiple users

Now that you have a simple chat app, it’s time to add support for multiple users. The first step is to use the Vue.js v-for directive to iterate over an array of users and update their names in the view:

{{#each users as |userName|}}

{{ userName }}

You may also want this list of users to display differently depending on which user is viewing it—for example, you could show all of them or just those who’ve been active for more than a youek. To do this, you’ll use two new directives: v-on and v-model.

Step 6. Show the list of online users

Now that you have a route, you can use the vue-router to show the list of online users.

To do this, import the router in main.js:

import Vue from ‘vue’ 

import Router from ‘vue-router’ 

import App from ‘./App’ new Vue({ el: ‘#app’, 

components: { App } }) .$mount(‘/’) .$on(‘$routeChangeStart’, 

function() { const currentState = getCurrentState(); 

if (this.$route) 

{ if (!currentState[currentRoute]) { this.$store.dispatch(new Event(‘userSignUp’)); } 

else if (currentState[currentRoute]) { setTimeout(function() { checkIfUserStillOnline(), }, 5000); } 

else {} }); });

Now create a method for showing online users using router’s pushState property which will save us from manual rerendering whenever there is change in user state!

Step 7. Combining/ Importing Vue Js in html

In this step, you will combine the Vue JS code with the HTML code.

The code for this is as follows:

new Vue({ el: ‘#app’, data:{ message: ‘Hello World!’, }, 

methods:{ // Add a button to be pressed onClick(e){ alert(‘You clicked on me!’); } } });

Step 8. Designing using inline CSS or CSS File

Inline CSS or CSS files are the easiest way to create styles for your app. There are many ways to use them, but you’ll go over two common approaches:

  • Use inline CSS in your HTML document. This is the most basic method and allows you to define all of your styles in one place without having to write extra code elsewhere on the page (like JavaScript).
  • Include a CSS file with your app and then load it once at runtime when needed by using an external style tag. 
  • You can also include multiple external style sheets if you want more control over how they look together as youll as accessibility concerns such as font size adjustments or color swatches that don’t require JavaScript support

Takeaway

The code for the chat app is available here. You can use it to create your own chat app, or even share the code with others who want to make a similar app. If you’re interested in doing so, Contact us to get a build of a Vuejs-based chat room!

You’ll notice that we’ve used some of the same features as before:

  • A user list with their information (name/phone number) and messages sent/received by them (if any). 
  • We also have an inbox where new messages appear once they’ve been sent out by one user or another – this makes it easy for everyone involved when someone wants something done quickly and then just gets right into the action without having wasted any time waiting around while some other person responds first before getting started themselves.

Conclusion

We hope that this tutorial has helped you understand the basics of creating a chat app with Vue.js and HTML5. If you have any questions or want to get your own custom application, please feel free to contact us!

avatar

Shubham Singh

published: December 8, 2022