Search code examples
javascriptnode.jsvue.jsejs

Vue.js is where side?


I learned one hour for watching videos (YouTube : One hour vue.js)

But i don't understand what is this language!

I developed some web site use Node.js and Jquery....Mongodb

I think web applications need two part like (apache,Mysql, Node.js....etc)

But Vue.js is really strange because vue.js just one side but provide web just typing 'npm strat'

I don't understand this......

If i want find Database's some data how to get these?

Is there a only way like use Ajax??

Should i use methods only to communicate with the server?

Is there only this way?

Can not i use the same syntax as ejs in vue.js?

 created : function(){
        this.$http.get('https://jsonplaceholder.typicode.com/users')
        .then(function(res){
            this.users = res.data;
        });

Solution

  • Vue.js is a frontend javascript framework. It will be on the same "side" as jQuery most of the time (jQuery could be used on the server side in a NodeJS application).

    You can use Ajax in Vue.js, but Vue.js does not come bundled with an http client out-of-the-box. So you cannot use this.$http right away. If you use Vue.js with Laravel, you may use axios to do queries.

    axios.get('/my-endpoint')
       .then(response => this.data = response.data);
    

    If you really want to use this.$http syntax, you could do something like this:

    import Vue from 'vue';
    import MyHttpClient from 'custom-http-client';
    
    Vue.$http = MyHttpClient;
    

    You would then have access to MyHttpClient in all Vue Components. Though I would recommend using Vue Plugin system to do so.

    If you are more confortable you may use jQuery's http client

    import $ from jquery;
    
    [...]
    
    $.get('/my-endpoint', function (response) { ... })
    

    You may use es6 syntax in Vue.js but you need to compile your Vue.js application using babel transpiler or any other transpiler out there.

    For the npm start part, I assume you are using vue-cli and that you built a webpack application. If that is so, you then started a local development server. Webpack includes a server so you can code your component locally.

    Using a webpack local server won't give you a full fledged backend. You might want to use any PHP, Python, Ruby, NodeJS or any other backend framework with a database. Hope this helps you figuring out what Vue.js is.