Showing posts with label vue. Show all posts
Showing posts with label vue. Show all posts

Wednesday, 6 January 2021

Complete Guide on JavaScript Frameworks for Frontend Development

Complete Guide on JavaScript Frameworks for Frontend Development


You don’t need to be tech-savvy to understand the concept of web and app development. We live in an increasingly technological world, and so it’s only normal to adapt to all the new changes.

Even if you don’t have the slightest idea about how web development works, we can lay it out for you. We all surf through the internet and watch things unfold, and you might know that everything runs smoothly because of programming.

Our computers need commands and a language to do all the tasks. So, that is how you get what you need. However, to paint a better picture for you, here’s a little introduction:

What is JavaScript?


So, mostly we have all seen how different web pages work, and different programming languages are responsible for everything. For instance, you see HTML and CSS that provide the format and style for websites.

However, JavaScript is a text-based language that is mainly responsible for creating interactive elements of a web page that help users take action. You log onto a website and see pop-ups, a sign up for a newsletter, a web form, compelling graphics, or anything moving around; that is because of JavaScript.

It has a lot of benefits because to stand out from the crowd; you need dynamic content that tempts your readers to engage with it. Today, everything is about making the user’s experience more positive and refreshing, so JavaScript is ideal for taking your web development up a notch. You can add any responsive elements you want to target any specific audience and boost your online traffic through JavaScript. Web developers are the reason behind us aimlessly surfing through different websites each day. You come across various styles, themes, sign up or log out buttons, required fields to check out a web page, all of this is done with the help of web developers.

For instance, it can be used in apps for small businesses, and you can create a catchy login button and have it do the job. Web developers create exciting features in web and mobile apps so you can have a memorable experience, and JS is behind it all.

What is the JavaScript Framework?


So, imagine you need to create a software or any application; you will need a step-by-step plan to accomplish this. That’s where frameworks come in handy because they are the blueprints of any app you want to build. It will help you gather everything you are going to need and help web developers achieve what they want.

Now, your application framework won’t do the job for you, but instead, it will help you using programs and libraries to create something that fulfils all your needs. JavaScript Framework is just a collection of different code libraries related to JavaScript.

It helps you save time and effort by providing you structure and assembling everything for you. You can reuse the same JavaScript code to create basic features for your applications. The frameworks help you add a little something to existing web pages instead of developing something new from scratch.

Frontend JavaScript Frameworks


There are two kinds of web and mobile app developers; backend and frontend. Now, the backend web developers are responsible for running the app, and frontend developers are responsible for how the app would work on its users’ devices.

There has been a lot of improvement and advancement in the tech and web development domain, so people no longer rely on HTML and CSS.

Nowadays, web applications can perform any task like paying a 2D/3D video, filling out required boxes, and engaging with the users. The whole world of all these new possibilities was introduced by Frontend JavaScript Frameworks that help your visitors stay hooked to the screen.

It is an application full of tactics that programmers can use to their advantage to create attention-grabbing and smooth web and mobile apps. It is all about making everything more convenient for you.



Why Do We Need the JS Frameworks?


Fundamentally, JavaScript Frameworks help achieve the following:

  • Give you all you require to make a web application
  • Furnish clients with formats to fabricate normal pieces of your web applications
  • Address an approach to make parts including directing, collecting information, structures, and static pages

You can’t just get by using catchy headlines and ads, you need to get your audience to engage with your content, and Frontend Web Development helps you build the most accessible user interface. JavaScript Frameworks are a high-level programming language, so they come with improved responsiveness.

1. Top JavaScript Frameworks


Following are by far the most commonly utilized JavaScript Frameworks:

1. React.js


This framework has been used for both Facebook and Instagram. It helps immensely with any kind of data management and lets you integrate with the rest of the code libraries. If you’re a web developer looking for something that helps you break down any code into little fragments, then the React.js framework is ideal for you.

2. Vue.js


Vue.js is the least complex option out of most of the JS frameworks. You can use it to create any kind of application because it has such a small size, so you can have all the features you want. Most web developers demand diversity when it comes to frameworks, and Vue.js will help you out in any department.

3. Angular


The angular framework gives you a wide platform and to explore any versatility you want. You can get several numbers activities done at the same time without facing any hassles.

Takeaway- A Definitive Guide on How Frontend JavaScript Frameworks Work


If you feel like you’re lost in the world of programming and coding, hopefully, this guide will help you out. It’s important to understand the basics and learn closely before you dive into the world of JavaScript frameworks.

You will need to choose the right type of framework for the kind of frontend development you wish to do, so make a wise choice. You can always opt for a framework that fulfils your criteria and then switches to another one for your project.

Author Bio:


Arslan Hassan is an electrical engineer with a passion for writing, designing, and anything tech-related. His educational background in the technical field has given him the edge to write on many topics. He occasionally writes blog articles for Apcelero.

Thursday, 30 April 2020

Vue js File Upload with PHP & Axios



This post will guide you to How to upload files using Vue.js with PHP script and Axios package. This post will help your to uploading files with VueJS with Axios. As a programmer we have already know file upload is one or the basic feature which has been required in any web based application for store or upload file on server. In this post, we will use Vue.js library & Axios package as front end technology and PHP will be use as back end technology for upload files on server.

For upload file, here we have use Axios package with Vue.js library, by using this Axios package we will send Ajax request for upload file. For send selected file here we have use FormData object, which will send file via Ajax request to PHP script. Do you know Vue.js and Axios package is work together for send HTTP requests. But here we want to send file via Ajax request for Uploading and it is little bit challenging task, because here we have to use Axios package for send file to PHP script. For this here we have use FormData() object for send selected file to PHP script via Ajax request. This tutorial will provide you simple and quick guide for handle file upload process in VueJS with PHP script.







First we have to import Vue.js and Axios package in our working index page. For this you can see below code in which we have import VueJS library and Axios package link at the header of file.


<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>


First in Vue application, we have to define element for Vue appliction. For this we have to define in any tag with id="uploadApp" This attribute value will be used in the property of el: which binds the new Vue object to HTML tag with id="uploadApp".


<div class="container" id="uploadApp">

</div>


After for display upload file validation error and success message, here we have use Bootstrap alert class. Within Bootstrap alert class we have use v-if directive for display alert message on condition. If this v-if directive value is equal to true then it will display validation error or success message on web page, otherwise it will be hide from web page. Same way for display dynamic error or success message, here we have use double braces {{ }} as place-holders for data. This data value will be define on different event.


<div class="container" id="uploadApp">
   <br />
   <h3 align="center">How to upload file using Vue.js with PHP</h3>
   <br />
   <div v-if="successAlert" class="alert alert-success alert-dismissible">
    <a href="#" class="close" aria-label="close" @click="successAlert=false">&times;</a>
    {{ successMessage }}
   </div>

   <div v-if="errorAlert" class="alert alert-danger alert-dismissible">
    <a href="#" class="close" aria-label="close" @click="errorAlert=false">&times;</a>
    {{ errorMessage }}
   </div>
</div>


After this we have to create input file tag for select image or file from local computer. In input file tag we have use ref='file' which will be used for get the selected file in Vue Script.

Once file has been selected then for upload file on server, here we have define one button tag. In that button we have define @click directive. So when we have click on button, then it will called uploadImage() function.

After uploading of image, now we want to display on web page. So here we have create on div tag and under that tag we have use v-html directive. This directive is used to display HTML code under that tag.


<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>How to upload file using Vue.js with PHP</title>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  
 </head>
 <body>
  <div class="container" id="uploadApp">
   <br />
   <h3 align="center">How to upload file using Vue.js with PHP</h3>
   <br />
   <div v-if="successAlert" class="alert alert-success alert-dismissible">
    <a href="#" class="close" aria-label="close" @click="successAlert=false">&times;</a>
    {{ successMessage }}
   </div>

   <div v-if="errorAlert" class="alert alert-danger alert-dismissible">
    <a href="#" class="close" aria-label="close" @click="errorAlert=false">&times;</a>
    {{ errorMessage }}
   </div>
   <div class="panel panel-default">
    <div class="panel-heading">
     <div class="row">
      <div class="col-md-6">
       <h3 class="panel-title">Upload File</h3>
      </div>
      <div class="col-md-6" align="right">
       
      </div>
     </div>
    </div>
    <div class="panel-body">
     <div class="row">
      <div class="col-md-4" align="right">
       <label>Select Image</label>
      </div>
      <div class="col-md-4">
       <input type="file" ref="file" />
      </div>
      <div class="col-md-4">
       <button type="button" @click="uploadImage" class="btn btn-primary">Upload Image</button>
      </div>
     </div>
     <br />
     <br />
     <div v-html="uploadedImage" align="center"></div>
    </div>
   </div>
  </div>
 </body>
</html>





So, here our HTML code part is ready, now we have go to Vue.js code part. In this part, Vue JS has been initialize on #uploadApp.

After this, we have to define data for Vue.js application, here we have to define file variable with blank value, successAlert with false value for hide success message from web page, and same way for hide error alert message here also we have define errorAlert variable with false value. For clear uploaded image division tag data, here also we have set uploadImage variable with blank value.

After define data, we have to define methods, so in this section we have create uploadImage() function which will be called after click on upload button. In this function, first we have add selected file in Vue JS for send selected file to PHP script. Here we have use FormData object for send selected file to PHP script. We will append selected file in FormData() object as data.

After appending data in formData as data, we want to send POST request to upload.php file and pass formData in which we have append selected file has been send with post request as data. We have also set Content-Type: 'multipart/form-data' in header. Once image has been successfully uploaded then it will display success message on web page with uploaded image and suppose there is any error occur during uploading of file then it will display validation error on web page.


<script>

var application = new Vue({
 el:'#uploadApp',
 data:{
  file:'',
  successAlert:false,
  errorAlert:false,
  uploadedImage:'',
 },
 methods:{
  uploadImage:function(){

   application.file = application.$refs.file.files[0];

   var formData = new FormData();

   formData.append('file', application.file);

   axios.post('upload.php', formData, {
    header:{
     'Content-Type' : 'multipart/form-data'
    }
   }).then(function(response){
    if(response.data.image == '')
    {
     application.errorAlert = true;
     application.successAlert = false;
     application.errorMessage = response.data.message;
     application.successMessage = '';
     application.uploadedImage = '';
    }
    else
    {
     application.errorAlert = false;
     application.successAlert = true;
     application.errorMessage = '';
     application.successMessage = response.data.message;
     var image_html = "<img src='"+response.data.image+"' class='img-thumbnail' width='200' />";
     application.uploadedImage = image_html;
     application.$refs.file.value = '';
    }
   });
  }
 },
});
</script>


upload.php


So here our HTML and Vue JS code is ready now we have move to write PHP code in upload.php file. This file will first check user has select file or not, if user has not select file then it will display validation error.

If User has select file, then it will proceed for another validation and it will check selected file has valid extension. If selected file has not valid extension then it will display validation error on web page.

If Selected file has valid extension, then it will first create new name for selected file before uploading of image. After this it will upload selected image file in upload directive and send success message with uploaded image path as data to Axios request in json format. Below you can find complete PHP script for upload image in upload directive.


<?php

//upload.php

$image = '';

if(isset($_FILES['file']['name']))
{
 $image_name = $_FILES['file']['name'];
 $valid_extensions = array("jpg","jpeg","png");
 $extension = pathinfo($image_name, PATHINFO_EXTENSION);
 if(in_array($extension, $valid_extensions))
 {
  $upload_path = 'upload/' . time() . '.' . $extension;
  if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_path))
  {
   $message = 'Image Uploaded';
   $image = $upload_path;
  }
  else
  {
   $message = 'There is an error while uploading image';
  }
 }
 else
 {
  $message = 'Only .jpg, .jpeg and .png Image allowed to upload';
 }
}
else
{
 $message = 'Select Image';
}

$output = array(
 'message'  => $message,
 'image'   => $image
);

echo json_encode($output);


?>


So, this is complete step by step guide for upload file using Vue.js with PHP script and Axios package. I hope you have understand this file uploading process using VueJS with PHP script.