Mya Dopkova

Mya Dopkova

1570694921

How to Build Feedback Application with Vue.js

Here is a screen recording of what our application will be able to do once we are done building it:

This is image title

Requirements we will need to build our application

Before we get started we need to have a few things in place first. Some of the requirements are as follows:

  • Knowledge of PHP & the Laravel framework.
  • Knowledge of JavaScript (ES6).
  • Knowledge of Vue.js.
  • PHP 7.0+ installed locally on your machine.
  • Laravel CLI installed locally.
  • Composer installed locally.
  • NPM and Node.js installed locally.
  • A Pusher application.

Once you have verified you have the above requirements we can start creating our application.

Setting up our prototype feedback application

Let us get started with setting up our application. Create a new Laravel application using the command below:

    $ laravel new your_application_name

When the installation is complete, cd to the application directory. Open the .env file and let us make a couple of changes in the file.

Setting up our database and migrations

The first thing to do is set up our database and create its migrations. Let us start by setting up the database. Replace the configuration items below:

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=homestead
    DB_USERNAME=homestead
    DB_PASSWORD=secret

with:

    DB_CONNECTION=sqlite

This will now make the application use SQLite as the database choice. In your terminal, run the command below to create a new SQLite database:

    $ touch database/database.sqlite

Now let us create some migrations which will create the required tables to the database. In your terminal, run the following command to create the migrations we will need:

    $ php artisan make:model Photo --migration --controller
    $ php artisan make:model PhotoComment --migration

The above command will create a model and then the --migration and --controller flags will instruct it to create a migration and a controller alongside the model.

For now, we are interested in the Model and the migration. Open the two migration files created in the ./database/migrations directory. Let us first edit the CreatePhotosTable class. Replace the content of the up method with the following below:

    public function up()
    {
        Schema::create('photos', function (Blueprint $table) {
            $table->increments('id');
            $table->string('url')->unique();
            $table->string('image')->unique();
            $table->timestamps();
        });
    }

This will create the photos table when the migrations are run using the artisan command. It will also create new columns inside the table as specified above.

Open the second migration class, CreatePhotoCommentsTable, and replace the up method with the contents below:

    public function up()
    {
        Schema::create('photo_comments', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('photo_id');
            $table->text('comment');
            $table->integer('top')->default(0);
            $table->integer('left')->default(0);
            $table->timestamps();

            $table->foreign('photo_id')->references('id')->on('photos');
        });
    }

This will create the table photo_comments when the migration is run and also will create a foreign key to the photos table.

Now go to your terminal and run the command below to run the migrations:

    $ php artisan migrate

This should now create the database tables.

Setting up the models

Now that we have run our migrations, we need to make some changes to our model file so that it can work better with the table.

Open the Photo model and replace the contents with the following:

    <?php
    namespace App;

    use Illuminate\Database\Eloquent\Model;

    class Photo extends Model
    {
        protected $with = ['comments'];

        protected $fillable = ['url', 'image'];

        public function comments()
        {
            return $this->hasMany(PhotoComment::class);
        }
    }

In the above, we have added the fillable property which stops us from having mass assignment exceptions when trying to update those columns using Photo::create. We also set the with property which just eager loads the comments relationship.

We have defined an Eloquent relationship comments that just says the Photo has many PhotoComments.

Open the PhotoComment model and replace the contents with the following:

    <?php
    namespace App;

    use Illuminate\Database\Eloquent\Model;

    class PhotoComment extends Model
    {
        protected $fillable = ['photo_id', 'comment', 'top', 'left'];

        protected $appends = ['position'];

        public function getPositionAttribute()
        {
            return [
                'top' => $this->attributes['top'], 
                'left' => $this->attributes['left']
            ];
        }
    }

Just like the Photo model, we have defined the fillable property. We also use Eloquent accessors to configure a new property called position which is then appended because we specified that in the appends property.

Setting up the frontend for our application

The next thing we want to do is set up the frontend of our application. Let us start by installing a few NPM packages that we will need in the application. In your Terminal app, run the command below to install the needed packages:

    $ npm install --save laravel-echo pusher-js vue2-dropzone@^2.0.0
    $ npm install

This will install Laravel Echo, the Pusher JS SDK and vue-dropzone. We will need these packages to handle realtime events later.

When the packages have been installed successfully, we can now start adding some HTML and JavaScript.

Open the ./routes/web.php file and let’s add some routes. Replace the contents of the file with the contents below:

    <?php

    Route::post('/feedback/{image_url}/comment', 'PhotoController@comment');
    Route::get('/feedback/{image_url}', 'PhotoController@show');
    Route::post('/upload', 'PhotoController@upload');
    Route::view('/', 'welcome');

In the code above, we have defined a few routes. The first one will be handling POSTed feedback. The second route will display the image that is to receive feedback. The third route will handle uploads and the final route will display the homepage.

Now open the ./resources/views/welcome.blade.php file and in there replace the contents with the following HTML code:

    <!doctype html>
    <html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{csrf_token()}}">
        <title>Upload to get Feedback</title>
        <link href="https://fonts.googleapis.com/css?family=Roboto:400,600" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <link rel="stylesheet" href="{{ asset('css/app.css') }}">
    </head>
    <body>
        <div id="app">
            <div class="flex-center position-ref full-height">
                <div class="content">
                    <uploadarea></uploadarea>
                </div>
            </div>
        </div>
        <script src="js/app.js"></script>
    </body>
    </html>

This is a simple HTML document, and if you look closely, you will see a reference to an uploadarea tag which does not exist in HTML but is a Vue component.

Open the ./resources/assets/sass/app.scss file and paste the following code below the import statements:

    html, body {
        background-color: #fff;
        color: #636b6f;
        font-family: 'Roboto', sans-serif;
        font-weight: 100;
        height: 100vh;
        margin: 0;
    }
    .full-height {
        height: 100vh;
    }
    .flex-center {
        align-items: center;
        display: flex;
        justify-content: center;
    }
    .position-ref {
        position: relative;
    }
    .content {
        text-align: center;
    }
    .m-b-md {
        margin-bottom: 30px;
    }
    .dropzone.dz-clickable {
        width: 100vw;
        height: 100vh;
        .dz-message {
            span {
                font-size: 19px;
                font-weight: 600;
            }
        }
    }
    #canvas {
        width: 90%;
        margin: 0 auto;
        img {
            width: 100%;
        }
    }
    .modal {
      text-align: center;
      padding: 0!important;
      z-index: 9999;
    }
    .modal-backdrop.in {
        opacity: 0.8;
        filter: alpha(opacity=80);
    }
    .modal:before {
      content: '';
      display: inline-block;
      height: 100%;
      vertical-align: middle;
      margin-right: -4px;
    }
    .modal-dialog {
      display: inline-block;
      text-align: left;
      vertical-align: middle;
    }
    .image-hotspot {
        position: relative;
        > img {
            display: block;
            height: auto;
            transition: all .5s;
        }
    }
    .hotspot-point {
        z-index: 2;
        position: absolute;
        display: block;
        span {
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
            width: 1.8em;
            height: 1.8em;
            background: #cf00f1;
            border-radius: 50%;
            animation: pulse 3s ease infinite;
            transition: background .3s;
            box-shadow: 0 2px 10px rgba(#000, .2);
            &:after {
                content: attr(data-price);
                position: absolute;
                bottom: 130%;
                left: 50%;
                color: white;
                text-shadow: 0 1px black;
                font-weight: 600;
                font-size: 1.2em;
                opacity: 0;
                transform: translate(-50%, 10%) scale(.5);
                transition: all .25s;
            }
        }
        svg {
            opacity: 0;
            color: #cf00f1;
            font-size: 1.4em;
            transition: opacity .2s;
        }
        &:before,
        &:after  {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            pointer-events: none;
        }
        &:before {
            z-index: -1;
            border: .15em solid rgba(#fff, .9);
            opacity: 0;
            transform: scale(2);
            transition: transform .25s, opacity .2s;
        }
        &:after {
            z-index: -2;
            background:#fff;
            animation: wave 3s linear infinite;
        }
        &:hover{
            span {
                animation: none;
                background: #fff;
                &:after {
                    opacity: 1;
                    transform: translate(-50%, 0) scale(1);
                }
            }
            svg {
                opacity: 1;
            }
            &:before {
                opacity: 1;
                transform: scale(1.5);
                animation: borderColor 2s linear infinite;
            }
            &:after {
                animation: none;
                opacity: 0;
            }
        }
    }
    @-webkit-keyframes pulse{
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.1); }
    }
    @keyframes pulse{
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.1); }
    }
    .popover {
        min-width: 250px;
    }

Save the file and exit. Now let’s move on to creating our Vue components.

Using Vue to create the functionalities of our prototype feedback app

Open the ./resources/assets/js/app.js file and in there let us create our Vue component. In this file find the line below:

    Vue.component('example', require('./components/Example.vue'));

and replace it with:

    Vue.component('uploadarea', require('./components/UploadArea.vue'));
    Vue.component('feedback', require('./components/FeedbackCanvas.vue'));

Now let us create our first Vue component. In the ./resources/assets/js/components directory create a file called UploadArea.vue. In the new file paste in the following:

    <template>
        <dropzone ref="dropzone" id="dropzone"
                url="/upload"
                accepted-file-types="image/*"
                v-on:vdropzone-success="showImagePage"
                :headers="csrfHeader"
                class="flex-center position-ref full-height">
            <input type="hidden" name="csrf-token" :value="csrfToken">
        </dropzone>
    </template>

    <script>
    import Dropzone from 'vue2-dropzone';

    const LARAVEL_TOKEN = document.head.querySelector('meta[name="csrf-token"]').content

    export default {
        components: { Dropzone },
        data() {
            return {
                csrfToken: LARAVEL_TOKEN,
                csrfHeader: { 'X-CSRF-TOKEN': LARAVEL_TOKEN }
            }
        },
        methods: {
            showImagePage: (file, response) => {
                if (response.url) {
                    return window.location = `/feedback/${response.url}`;
                }
            }
        },
        mounted () {
            this.$refs.dropzone.dropzone.on('addedfile', function (file) {
                if (this.files.length > 1) {
                    this.removeFile(this.files[0])
                }
            })
        }
    }
    </script>

In the template section, we are simply using the Vue dropzone package to define an area through which files can be uploaded. You can view the documentation here.

In the script section, we get the Laravel CSRF token from the header of the page and import the Dropzone component into our current Vue component.

In the methods property, we define a showImagePage method that just redirects the user to the image page after the image has been successfully uploaded. In the mounted method, we limit the dropzone file to allowing one file upload at a time.

Let us create our next Vue component. In the ./resources/assets/js/components directory create a new file called FeedbackCanvas.vue and paste in the following:

    <template>
        <div class="feedback-area">
            <div class="content">
                <div id="canvas">
                    <div class="image-hotspot" id="imghotspot">
                        <transition-group name="hotspots">
                          <a
                            href="#"
                            class="hotspot-point"
                            v-for="(comment, index) in image.comments"
                            v-bind:style="{ left: comment.position.left+'%', top: comment.position.top+'%' }"
                            :key="index"
                            @click.prevent
                            data-placement="top"
                            data-toggle="popover"
                            :data-content="comment.comment"
                          >
                                <span>
                                    <svg class="icon icon-close" viewBox="0 0 24 24">
                                        <path d="M18.984 12.984h-6v6h-1.969v-6h-6v-1.969h6v-6h1.969v6h6v1.969z"></path>
                                    </svg>
                                </span>
                          </a>
                        </transition-group>
                        <img ref="img" :src="'/storage/'+image.image" id="loaded-img"  @click="addCommentPoint">
                    </div>
                </div>
            </div>
            <add-comment-modal :image="image"></add-comment-modal>
        </div>
    </template>

We have defined the template for our Vue component. This is the area where the image will be displayed and where feedback will be given.

Let us break some parts of it down a little. The a tag has a bunch of attributes set to it. The v-for loops through each comment/feedback the image has.

The v-bind:style applies a style attribute to the a tag using the left and top properties of the comment/feedback. We also have the :data-content, data-toggle and data-placement which Bootstrap needs for its Popovers.

The img tag has the @click event that fires the function addCommentPoint when an area of the image is clicked. And finally, there’s a Vue component add-comment-modal that accepts a property image. This component will display a form so anyone can leave a comment.

In this same file, after the closing template tag, paste in the following code:

    <script>
        let AddCommentModal = require('./AddCommentModal.vue')

        export default {
            props: ['photo'],
            components: { AddCommentModal },
            data() {
                return { image: this.photo }
            },
            mounted() {
                let vm = this

                Echo.channel(`feedback-${this.photo.id}`)
                    .listen('.added', (e) => {
                        // Look through the comments and if no comment matches the 
                        // existing comments, add it
                        if (vm.image.comments.filter((comment) => comment.id === e.comment.id).length === 0) {
                            vm.image.comments.push(e.comment)
                            $(document).ready(() => $('[data-toggle="popover"]').popover())
                        }
                    })
            },
            created() {
                /** Activate popovers */
                $(document).ready(() => $('[data-toggle="popover"]').popover());

                /** Calculates the coordinates of the click point */
                this.calculateClickCordinates = function (evt) {
                    let rect = evt.target.getBoundingClientRect()
                    return {
                        left: Math.floor((evt.clientX - rect.left - 7) * 100 / this.$refs.img.width),
                        top: Math.floor((evt.clientY - rect.top - 7) * 100 / this.$refs.img.height)
                    }
                }

                /** Removes comments that have not been saved */
                this.removeUnsavedComments = function () {
                    var i = this.image.comments.length
                    while (i--) {
                        if ( ! this.image.comments[i]['id']) {
                            this.image.comments.splice(i, 1)
                        }
                    }
                }
            },
            methods: {
                addCommentPoint: function(evt) {
                    let vm       = this
                    let position = vm.calculateClickCordinates(evt)
                    let count    = this.image.comments.push({ position })

                    // Show the modal and add a callback for when the modal is closed
                    let modalElem = $("#add-modal")
                    modalElem.data({"comment-index": count-1, "comment-position": position})
                    modalElem.modal("show").on("hide.bs.modal", () => vm.removeUnsavedComments())
                }
            },
        }
    </script>

You may also like: Angular vs React vs Vue: Which one will be popular in 2020.

In the mounted method, we use Laravel Echo to listen to a Pusher channel. The channel name depends on the ID of the image currently being viewed. Each image will have broadcasts on a different channel based on the ID of the image.

When the added event is triggered on the feedback-$id channel, it looks through the available image.comments and, if the comment broadcasted does not exist, it adds it to the comments array.

In the create method, We activate Bootstrap popovers, define a function that calculates the coordinates of the click point, and we define a function that removes comments that have not been saved from the image.comments array.

Under methods we define the addCommentPoint method which calculates the click coordinates, and then launches a new Bootstrap modal which is going to be created in the add-comment-modal Vue component.

For Laravel Echo to work, we need to open the ./resources/assets/js/bootstrap.js file and add the code below at the bottom of the file:

    import Echo from 'laravel-echo'

    window.Pusher = require('pusher-js');

    window.Echo = new Echo({
        broadcaster: 'pusher',
        key: 'PUSHER_KEY',
        encrypted: true,
        cluster: 'PUSHER_CLUSTER'
    });

You should replace PUSHER_KEY and PUSHER_CLUSTER with the key and cluster for your Pusher application.

Now lets create our next Vue component, AddCommentModal.vue. It is already referenced in our FeedbackCanvas.vue Vue component.

Create an AddCommentModal.vue file in the same directory as our other Vue components. In this file paste in the code below:

    <template>
      <div id="add-modal" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false">
          <div class="modal-dialog">
              <div class="modal-content">
                  <form method="post" :action="'/feedback/'+photo.url+'post'" @submit.prevent="submitFeedback()">
                      <div class="modal-header">
                          <h4 class="modal-title">Add Feedback</h4>
                      </div>
                      <div class="modal-body">
                          <textarea name="feedback" id="feedback-provided" cols="10" rows="5" class="form-control" v-model="feedback" placeholder="Enter feedback..." required minlength="2" maxlength="2000"></textarea>
                      </div>
                      <div class="modal-footer">
                          <button type="submit" class="btn btn-primary pull-right">Submit</button>
                          <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
                      </div>
                  </form>
              </div>
        </div>
      </div>
    </template>

    <script>
    export default {
        props: ['image'],
        data() {
            return { photo: this.image, feedback: null }
        },
        methods: {
            submitFeedback: function () {
                let vm = this
                let modal = $('#add-modal')
                let position = modal.data("comment-position")

                // Create url and payload
                let url = `/feedback/${this.photo.url}/comment`;
                let payload = {comment: this.feedback, left: position.left, top: position.top}
                axios.post(url, payload).then(response => {
                    this.feedback = null
                    modal.modal('hide')
                    vm.photo.comments[modal.data('comment-index')] = response.data
                    $(document).ready(() => $('[data-toggle="popover"]').popover())
                })
            }
        }
    }
    </script>

In the template section, we have defined a typical Bootstrap modal. In the modal form, we have attached a call to submitFeedback() which is triggered when the form is submitted.

In the script section, we have defined the submitFeedback() method in the methods property of the Vue component. This function simply sends a comment to the backend for storage. If there is a favorable response from the API, the Bootstrap modal is hidden and the comment is appended to the image.comments array. The Bootstrap popover is then reloaded so it picks up the changes.

With that final change, we have defined all our Vue components. Open your terminal and run the command below to build your JS and CSS assets:

    $ npm run dev

Great! Now let’s build the backend.

Creating the Endpoints for our prototype feedback application

In your terminal, enter the command below:

    php artisan make:event FeedbackAdded

This will create an event class called FeedbackAdded. We will use this file to trigger events to Pusher when we add some feedback.This will make feedback appear in realtime to anyone looking at the image.

Open the PhotoController class and replace the contents with the code below:

    <?php
    namespace App\Http\Controllers;

    use App\Events\FeedbackAdded;
    use App\{Photo, PhotoComment};

    class PhotoController extends Controller
    {
        public function show($url)
        {
            $photo = Photo::whereUrl($url)->firstOrFail();

            return view('image', compact('photo'));
        }

        public function comment(string $url)
        {
            $photo = Photo::whereUrl($url)->firstOrFail();

            $data = request()->validate([
                "comment" => "required|between:2,2000",
                "left" => "required|numeric|between:0,100",
                "top"  => "required|numeric|between:0,100",
            ]);

            $comment = $photo->comments()->save(new PhotoComment($data));

            event(new FeedbackAdded($photo->id, $comment->toArray()));

            return response()->json($comment);
        }

        public function upload()
        {
            request()->validate(['file' => 'required|image']);

            $gibberish = md5(str_random().time());

            $imgName = "{$gibberish}.".request('file')->getClientOriginalExtension();

            request('file')->move(public_path('storage'), $imgName);

            $photo = Photo::create(['image' => $imgName, 'url' => $gibberish]);

            return response()->json($photo->toArray());
        }
    }

In the above, we have a show method which shows an image so people can leave feedback on it. Next, there is the comment method that saves a new comment on an image. The final method is the upload method that simply uploads an image to the server and saves it to the database.

Let us create the view for the show method. Create a new file in the ./resources/views directory called image.blade.php. In this file, paste the code below:

    <!doctype html>
    <html lang="{{ app()->getLocale() }}">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{csrf_token()}}">
        <title>Laravel</title>
        <link href="https://fonts.googleapis.com/css?family=Roboto:400,600" rel="stylesheet" type="text/css">
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
        <link rel="stylesheet" href="{{ asset('css/app.css') }}">
    </head>
    <body>
        <div id="app">
            <feedback :photo='@json($photo)'></feedback>
        </div>
        <script src="{{asset('js/app.js')}}"></script>
    </body>
    </html>

In the above, the only thing that stands out is the feedback tag and it is basically in reference to the feedback Vue component we built earlier in the article. Every other thing is just basic Blade and HTML.

Now that we have created the view, we need to add the directory for uploads defined in the upload method. In your terminal, run the command below:

    $ php artisan storage:link

This command will create a symlink from the ./storage directory to the ./public/storage directory. If you look in the ./public directory you should see the symlink.

Now that we have created the backend to support our web application, we need to add Pusher to the backend so that the comments made are broadcasted and can be picked up by other people browsing the image.

Adding realtime functionality to the prototype feedback app using Pusher

Open your terminal and enter the command below to install

    $ composer require pusher/pusher-php-server "~3.0" 

Open the .env file and scroll to the bottom and configure the Pusher keys as seen below:

    PUSHER_APP_ID="PUSHER_ID"
    PUSHER_APP_KEY="PUSHER_KEY"
    PUSHER_APP_SECRET="PUSHER_SECRET" 

Also in the same file, look for the BROADCAST_DRIVER and change it from log to pusher.

Next, open the ./config/broadcasting.php and scroll to the pusher key. Replace the options key of that configuration to the code below:

    // ...
    'options' => [
        'cluster' => 'PUSHER_CLUSTER',
        'encrypted' => true
    ], 
    // ...

💡 Remember to replace the PUSHER_ID, PUSHER_KEY, PUSHER_SECRET and PUSHER_CLUSTER with the values from your Pusher application.

Now, open the FeedbackAdded class and replace the contents with the code below:

    <?php

    namespace App\Events;

    use Illuminate\Broadcasting\Channel;
    use Illuminate\Queue\SerializesModels;
    use Illuminate\Foundation\Events\Dispatchable;
    use Illuminate\Broadcasting\InteractsWithSockets;
    use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

    class FeedbackAdded implements ShouldBroadcast
    {
        use Dispatchable, InteractsWithSockets, SerializesModels;

        public $comment;

        public $photo_id;

        public function __construct(int $photo_id, array $comment)
        {
            $this->comment = $comment;
            $this->photo_id = $photo_id;
        }

        public function broadcastOn()
        {
            return new Channel("feedback-{$this->photo_id}");
        }

        public function broadcastAs()
        {
            return 'added';
        }
    }

In the class above, we define the comment object and the photo_id which will be used to compose the channel name in the broadcastOn method. We also define the broadcastAs method which will allow us to customise the name of the event being sent to Pusher.

That’s all. Now, let’s run our application. In your terminal, run the code below:

    $ php artisan serve

This should start a new PHP server and you can then use that to test your application. Go to the URL given and you should see your application.

You may also like: How to Write better VueJS code.

Conclusion

In this article, we have successfully created a prototype application’s feedback feature that will allow designers share their designs with others and receive feedback on them.

Thank for reading, I hope this tutorial will surely help and you if you liked this tutorial, please consider sharing it with others.

#vue-js #javascript #php #laravel #web-development

What is GEEK

Buddha Community

How to Build Feedback Application with Vue.js
Aria Barnes

Aria Barnes

1625232484

Why is Vue JS the most Preferred Choice for Responsive Web Application Development?

For more than two decades, JavaScript has facilitated businesses to develop responsive web applications for their customers. Used both client and server-side, JavaScript enables you to bring dynamics to pages through expanded functionality and real-time modifications.

Did you know!

According to a web development survey 2020, JavaScript is the most used language for the 8th year, with 67.7% of people choosing it. With this came up several javascript frameworks for frontend, backend development, or even testing.

And one such framework is Vue.Js. It is used to build simple projects and can also be advanced to create sophisticated apps using state-of-the-art tools. Beyond that, some other solid reasons give Vuejs a thumbs up for responsive web application development.

Want to know them? Then follow this blog until the end. Through this article, I will describe all the reasons and benefits of Vue js development. So, stay tuned.

Vue.Js - A Brief Introduction

Released in the year 2014 for public use, Vue.Js is an open-source JavaScript framework used to create UIs and single-page applications. It has over 77.4 million likes on Github for creating intuitive web interfaces.

The recent version is Vue.js 2.6, and is the second most preferred framework according to Stack Overflow Developer Survey 2019.

Every Vue.js development company is widely using the framework across the world for responsive web application development. It is centered around the view layer, provides a lot of functionality for the view layer, and builds single-page web applications.

Some most astonishing stats about Vue.Js:

• Vue was ranked #2 in the Front End JavaScript Framework rankings in the State of JS 2019 survey by developers.

• Approximately 427k to 693k sites are built with Vue js, according to Wappalyzer and BuiltWith statistics of June 2020.

• According to the State of JS 2019 survey, 40.5% of JavaScript developers are currently using Vue, while 34.5% have shown keen interest in using it in the future.

• In Stack Overflow's Developer Survey 2020, Vue was ranked the 3rd most popular front-end JavaScript framework.

Why is Vue.Js so popular?

• High-speed run-time performance
• Vue.Js uses a virtual DOM.
• The main focus is on the core library, while the collaborating libraries handle other features such as global state management and routing.
• Vue.JS provides responsive visual components.

Top 7 Reasons to Choose Vue JS for Web Application Development

Vue js development has certain benefits, which will encourage you to use it in your projects. For example, Vue.js is similar to Angular and React in many aspects, and it continues to enjoy increasing popularity compared to other frameworks.

The framework is only 20 kilobytes in size, making it easy for you to download files instantly. Vue.js easily beats other frameworks when it comes to loading times and usage.

Take a look at the compelling advantages of using Vue.Js for web app development.

#1 Simple Integration

Vue.Js is popular because it allows you to integrate Vue.js into other frameworks such as React, enabling you to customize the project as per your needs and requirements.

It helps you build apps with Vue.js from scratch and introduce Vue.js elements into their existing apps. Due to its ease of integration, Vue.js is becoming a popular choice for web development as it can be used with various existing web applications.

You can feel free to include Vue.js CDN and start using it. Most third-party Vue components and libraries are additionally accessible and supported with the Vue.js CDN.

You don't need to set up node and npm to start using Vue.js. This implies that it helps develop new web applications, just like modifying previous applications.

The diversity of components allows you to create different types of web applications and replace existing frameworks. In addition, you can also choose to hire Vue js developers to use the technology to experiment with many other JavaScript applications.

#2 Easy to Understand

One of the main reasons for the growing popularity of Vue.Js is that the framework is straightforward to understand for individuals. This means that you can easily add Vue.Js to your web projects.

Also, Vue.Js has a well-defined architecture for storing your data with life-cycle and custom methods. Vue.Js also provides additional features such as watchers, directives, and computed properties, making it extremely easy to build modern apps and web applications with ease.

Another significant advantage of using the Vue.Js framework is that it makes it easy to build small and large-scale web applications in the shortest amount of time.

#3 Well-defined Ecosystem

The VueJS ecosystem is vibrant and well-defined, allowing Vue.Js development company to switch users to VueJS over other frameworks for web app development.

Without spending hours, you can easily find solutions to your problems. Furthermore, VueJs lets you choose only the building blocks you need.

Although the main focus of Vue is the view layer, with the help of Vue Router, Vue Test Utils, Vuex, and Vue CLI, you can find solutions and recommendations for frequently occurring problems.

The problems fall into these categories, and hence it becomes easy for programmers to get started with coding right away and not waste time figuring out how to use these tools.

The Vue ecosystem is easy to customize and scales between a library and a framework. Compared to other frameworks, its development speed is excellent, and it can also integrate different projects. This is the reason why most website development companies also prefer the Vue.Js ecosystem over others.

#4 Flexibility

Another benefit of going with Vue.Js for web app development needs is flexibility. Vue.Js provides an excellent level of flexibility. And makes it easier for web app development companies to write their templates in HTML, JavaScript, or pure JavaScript using virtual nodes.

Another significant benefit of using Vue.Js is that it makes it easier for developers to work with tools like templating engines, CSS preprocessors, and type checking tools like TypeScript.

#5 Two-Way Communication

Vue.Js is an excellent option for you because it encourages two-way communication. This has become possible with the MVVM architecture to handle HTML blocks. In this way, Vue.Js is very similar to Angular.Js, making it easier to handle HTML blocks as well.

With Vue.Js, two-way data binding is straightforward. This means that any changes made by the developer to the UI are passed to the data, and the changes made to the data are reflected in the UI.

This is also one reason why Vue.Js is also known as reactive because it can react to changes made to the data. This sets it apart from other libraries such as React.Js, which are designed to support only one-way communication.

#6 Detailed Documentation

One essential thing is well-defined documentation that helps you understand the required mechanism and build your application with ease. It shows all the options offered by the framework and related best practice examples.

Vue has excellent docs, and its API references are one of the best in the industry. They are well written, clear, and accessible in dealing with everything you need to know to build a Vue application.

Besides, the documentation at Vue.js is constantly improved and updated. It also includes a simple introductory guide and an excellent overview of the API. Perhaps, this is one of the most detailed documentation available for this type of language.

#7 Large Community Support

Support for the platform is impressive. In 2018, support continued to impress as every question was answered diligently. Over 6,200 problems were solved with an average resolution time of just six hours.

To support the community, there are frequent release cycles of updated information. Furthermore, the community continues to grow and develop with backend support from developers.



Wrapping Up

VueJS is an incredible choice for responsive web app development. Since it is lightweight and user-friendly, it builds a fast and integrated web application. The capabilities and potential of VueJS for web app development are extensive.

While Vuejs is simple to get started with, using it to build scalable web apps requires professionalism. Hence, you can approach a top Vue js development company in India to develop high-performing web apps.

Equipped with all the above features, it doesn't matter whether you want to build a small concept app or a full-fledged web app; Vue.Js is the most performant you can rely on.

Original source

 

#vue js development company #vue js development company in india #vue js development company india #vue js development services #vue js development #vue js development companies

NBB: Ad-hoc CLJS Scripting on Node.js

Nbb

Not babashka. Node.js babashka!?

Ad-hoc CLJS scripting on Node.js.

Status

Experimental. Please report issues here.

Goals and features

Nbb's main goal is to make it easy to get started with ad hoc CLJS scripting on Node.js.

Additional goals and features are:

  • Fast startup without relying on a custom version of Node.js.
  • Small artifact (current size is around 1.2MB).
  • First class macros.
  • Support building small TUI apps using Reagent.
  • Complement babashka with libraries from the Node.js ecosystem.

Requirements

Nbb requires Node.js v12 or newer.

How does this tool work?

CLJS code is evaluated through SCI, the same interpreter that powers babashka. Because SCI works with advanced compilation, the bundle size, especially when combined with other dependencies, is smaller than what you get with self-hosted CLJS. That makes startup faster. The trade-off is that execution is less performant and that only a subset of CLJS is available (e.g. no deftype, yet).

Usage

Install nbb from NPM:

$ npm install nbb -g

Omit -g for a local install.

Try out an expression:

$ nbb -e '(+ 1 2 3)'
6

And then install some other NPM libraries to use in the script. E.g.:

$ npm install csv-parse shelljs zx

Create a script which uses the NPM libraries:

(ns script
  (:require ["csv-parse/lib/sync$default" :as csv-parse]
            ["fs" :as fs]
            ["path" :as path]
            ["shelljs$default" :as sh]
            ["term-size$default" :as term-size]
            ["zx$default" :as zx]
            ["zx$fs" :as zxfs]
            [nbb.core :refer [*file*]]))

(prn (path/resolve "."))

(prn (term-size))

(println (count (str (fs/readFileSync *file*))))

(prn (sh/ls "."))

(prn (csv-parse "foo,bar"))

(prn (zxfs/existsSync *file*))

(zx/$ #js ["ls"])

Call the script:

$ nbb script.cljs
"/private/tmp/test-script"
#js {:columns 216, :rows 47}
510
#js ["node_modules" "package-lock.json" "package.json" "script.cljs"]
#js [#js ["foo" "bar"]]
true
$ ls
node_modules
package-lock.json
package.json
script.cljs

Macros

Nbb has first class support for macros: you can define them right inside your .cljs file, like you are used to from JVM Clojure. Consider the plet macro to make working with promises more palatable:

(defmacro plet
  [bindings & body]
  (let [binding-pairs (reverse (partition 2 bindings))
        body (cons 'do body)]
    (reduce (fn [body [sym expr]]
              (let [expr (list '.resolve 'js/Promise expr)]
                (list '.then expr (list 'clojure.core/fn (vector sym)
                                        body))))
            body
            binding-pairs)))

Using this macro we can look async code more like sync code. Consider this puppeteer example:

(-> (.launch puppeteer)
      (.then (fn [browser]
               (-> (.newPage browser)
                   (.then (fn [page]
                            (-> (.goto page "https://clojure.org")
                                (.then #(.screenshot page #js{:path "screenshot.png"}))
                                (.catch #(js/console.log %))
                                (.then #(.close browser)))))))))

Using plet this becomes:

(plet [browser (.launch puppeteer)
       page (.newPage browser)
       _ (.goto page "https://clojure.org")
       _ (-> (.screenshot page #js{:path "screenshot.png"})
             (.catch #(js/console.log %)))]
      (.close browser))

See the puppeteer example for the full code.

Since v0.0.36, nbb includes promesa which is a library to deal with promises. The above plet macro is similar to promesa.core/let.

Startup time

$ time nbb -e '(+ 1 2 3)'
6
nbb -e '(+ 1 2 3)'   0.17s  user 0.02s system 109% cpu 0.168 total

The baseline startup time for a script is about 170ms seconds on my laptop. When invoked via npx this adds another 300ms or so, so for faster startup, either use a globally installed nbb or use $(npm bin)/nbb script.cljs to bypass npx.

Dependencies

NPM dependencies

Nbb does not depend on any NPM dependencies. All NPM libraries loaded by a script are resolved relative to that script. When using the Reagent module, React is resolved in the same way as any other NPM library.

Classpath

To load .cljs files from local paths or dependencies, you can use the --classpath argument. The current dir is added to the classpath automatically. So if there is a file foo/bar.cljs relative to your current dir, then you can load it via (:require [foo.bar :as fb]). Note that nbb uses the same naming conventions for namespaces and directories as other Clojure tools: foo-bar in the namespace name becomes foo_bar in the directory name.

To load dependencies from the Clojure ecosystem, you can use the Clojure CLI or babashka to download them and produce a classpath:

$ classpath="$(clojure -A:nbb -Spath -Sdeps '{:aliases {:nbb {:replace-deps {com.github.seancorfield/honeysql {:git/tag "v2.0.0-rc5" :git/sha "01c3a55"}}}}}')"

and then feed it to the --classpath argument:

$ nbb --classpath "$classpath" -e "(require '[honey.sql :as sql]) (sql/format {:select :foo :from :bar :where [:= :baz 2]})"
["SELECT foo FROM bar WHERE baz = ?" 2]

Currently nbb only reads from directories, not jar files, so you are encouraged to use git libs. Support for .jar files will be added later.

Current file

The name of the file that is currently being executed is available via nbb.core/*file* or on the metadata of vars:

(ns foo
  (:require [nbb.core :refer [*file*]]))

(prn *file*) ;; "/private/tmp/foo.cljs"

(defn f [])
(prn (:file (meta #'f))) ;; "/private/tmp/foo.cljs"

Reagent

Nbb includes reagent.core which will be lazily loaded when required. You can use this together with ink to create a TUI application:

$ npm install ink

ink-demo.cljs:

(ns ink-demo
  (:require ["ink" :refer [render Text]]
            [reagent.core :as r]))

(defonce state (r/atom 0))

(doseq [n (range 1 11)]
  (js/setTimeout #(swap! state inc) (* n 500)))

(defn hello []
  [:> Text {:color "green"} "Hello, world! " @state])

(render (r/as-element [hello]))

Promesa

Working with callbacks and promises can become tedious. Since nbb v0.0.36 the promesa.core namespace is included with the let and do! macros. An example:

(ns prom
  (:require [promesa.core :as p]))

(defn sleep [ms]
  (js/Promise.
   (fn [resolve _]
     (js/setTimeout resolve ms))))

(defn do-stuff
  []
  (p/do!
   (println "Doing stuff which takes a while")
   (sleep 1000)
   1))

(p/let [a (do-stuff)
        b (inc a)
        c (do-stuff)
        d (+ b c)]
  (prn d))
$ nbb prom.cljs
Doing stuff which takes a while
Doing stuff which takes a while
3

Also see API docs.

Js-interop

Since nbb v0.0.75 applied-science/js-interop is available:

(ns example
  (:require [applied-science.js-interop :as j]))

(def o (j/lit {:a 1 :b 2 :c {:d 1}}))

(prn (j/select-keys o [:a :b])) ;; #js {:a 1, :b 2}
(prn (j/get-in o [:c :d])) ;; 1

Most of this library is supported in nbb, except the following:

  • destructuring using :syms
  • property access using .-x notation. In nbb, you must use keywords.

See the example of what is currently supported.

Examples

See the examples directory for small examples.

Also check out these projects built with nbb:

API

See API documentation.

Migrating to shadow-cljs

See this gist on how to convert an nbb script or project to shadow-cljs.

Build

Prequisites:

  • babashka >= 0.4.0
  • Clojure CLI >= 1.10.3.933
  • Node.js 16.5.0 (lower version may work, but this is the one I used to build)

To build:

  • Clone and cd into this repo
  • bb release

Run bb tasks for more project-related tasks.

Download Details:
Author: borkdude
Download Link: Download The Source Code
Official Website: https://github.com/borkdude/nbb 
License: EPL-1.0

#node #javascript

Luna  Mosciski

Luna Mosciski

1600583123

8 Popular Websites That Use The Vue.JS Framework

In this article, we are going to list out the most popular websites using Vue JS as their frontend framework.

Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.

This framework was created by Evan You and still it is maintained by his private team members. Vue is of course an open-source framework which is based on MVVM concept (Model-view view-Model) and used extensively in building sublime user-interfaces and also considered a prime choice for developing single-page heavy applications.

Released in February 2014, Vue JS has gained 64,828 stars on Github, making it very popular in recent times.

Evan used Angular JS on many operations while working for Google and integrated many features in Vue to cover the flaws of Angular.

“I figured, what if I could just extract the part that I really liked about Angular and build something really lightweight." - Evan You

#vuejs #vue #vue-with-laravel #vue-top-story #vue-3 #build-vue-frontend #vue-in-laravel #vue.js

sophia tondon

sophia tondon

1618971133

Top 10 VueJS Development Companies To Know In 2021-22

Vue.js is one of the most used and popular frontend development, or you can say client-side development framework. It is mainly used to develop single-page applications for both web and mobile. Famous companies like GitLab, NASA, Monito, Adobe, Accenture are currently using VueJS.

Do You Know?

Around 3079 companies reportedly use Vue.js in their tech stacks.
At GitHub, VueJS got 180.9K GitHub stars, including 28.5K GitHub forks.
Observing the increasing usage of VueJS and its robust features, various industry verticals are preferring to develop the website and mobile app Frontend using VueJS, and due to this reason, businesses are focusing on hiring VueJS developers from the top Vue.js development companies.

But the major concern of the enterprises is how to find the top companies to avail leading VueJS development service? Let’s move further and know what can help you find the best VueJS companies.

Read More - https://www.valuecoders.com/blog/technology-and-apps/top-10-vuejs-development-companies/

#hire vue js developer #hire vue.js developers #hire vue.js developer, #hire vue.js developers, #vue js development company #vue.js development company

Top VueJS App Development Company in USA

AppClues Infotech is the best & most reliable VueJS App Development Company in USA that builds high-quality and top-notch mobile apps with advanced methodology. The company is focused on providing innovative & technology-oriented solutions as per your specific business needs.

The organization’s VueJS developers have high experience and we have the capability of handling small to big projects. Being one of the leading mobile app development company in USA we are using the latest programming languages and technologies for their clients.

Key Elements:

· Total year of experience - 8+

· Employees Strength - 120+

· Hourly Rate - $25 – $45 / hr

· Location - New York, USA

· Successfully launched projects - 450+

VueJS Development Services by AppClues Infotech

· Custom VueJS Development

· Portal Development Solutions

· Web Application Development

· VueJS Plugin Development

· VueJS Ecommerce Development

· SPA (Single Page App) Development

· VueJS Migration

Why Hire VueJS Developers from AppClues Infotech?

· Agile & Adaptive Development

· 8+ Years of Average Experience

· 100% Transparency

· Guaranteed Bug-free VueJS Solution

· Flexible Engagement Models

· On-Time Project Delivery

· Immediate Technical Support

If you have any project ideas for VueJS app development then share your requirements with AppClues Infotech to get the best solution for your dream projects.

For more info:
Share Yoru Requirements: https://www.appcluesinfotech.com/contact-us/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910
**

#top vue.js development company #vue.js app development company #best vue js development company #hire top vue js developers #hire top vue.js developers in usa #vue js development company usa