JavaScript Fetch data with Vue from Web API fetch data with react hooks,fetch data with react,fetch

You appear to already be using jQuery, so to load the Vue when the page is loaded you can update your code to the following:

$(function(){
  const v = new Vue({
    el: '#divContent',
    created: function () {
      this.loadData();
    },
    data: {
      content: 'loading',
      serverData: null
    },
    methods: {
      loadData: function (viewerUserId, posterUserId) {
        const that = this;
        $.ajax({
          contentType: "application/json",
          dataType: "json",
          url: "http://my-webapi/",
          method: "Post",
          success: response => this.serverData = response,
          error: err => alert('Error')
        });
      }
    }
  });  
})

The syntax above is using the jQuery.ready shorthand to create the Vue only after the page is loaded.

Without jQuery, you might want to listen for the DOMContentLoaded event.

Alternatively, just load the script that creates the Vue at the bottom of the page and not in the header.

Here is a complete, working example.

console.clear()

$(function(){
  const v = new Vue({
    el: '#divContent',
    created: function () {
      this.loadData();
    },
    data: {
      content: 'loading',
      serverData: null
    },
    methods: {
      loadData: function (viewerUserId, posterUserId) {
        $.ajax({
          contentType: "application/json",
          dataType: "json",
          url: "https://httpbin.org/post",
          data: JSON.stringify({testing: "some value"}),
          method: "Post",
          success: response => {
            this.content = "loaded"
            this.serverData = response.json
          },
          error: err => console.log('Error')
        });
      }
    }
  });  
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.9/vue.js"></script>
<div id="divContent" class="content">
  {{ content }}
  <hr>
  Response: <br>
  {{ serverData }}
</div>
Answer:1

I am facing a little problems with using Custom Palettes with Angular Material Framework. I still not understand myself to use custom theme. In angular config file. $mdThemingProvider.definePalette('...

I am facing a little problems with using Custom Palettes with Angular Material Framework. I still not understand myself to use custom theme. In angular config file. $mdThemingProvider.definePalette('...

How can I detect width and height of the camera to use it on canvas and maintain the proportions?? I need to detect width and height of the camera and then use it on a canvas. In the new canvas I ...

How can I detect width and height of the camera to use it on canvas and maintain the proportions?? I need to detect width and height of the camera and then use it on a canvas. In the new canvas I ...

  1. detect height width

I have a requirement where all the checked values in checkboxes should be displayed in a textarea. This part works perfectly fine, but the problem occurs when I uncheck the checkbox unchecked element ...

I have a requirement where all the checked values in checkboxes should be displayed in a textarea. This part works perfectly fine, but the problem occurs when I uncheck the checkbox unchecked element ...

  1. pivot table remove values heading
  2. pivot table remove values less than
  3. excel pivot table remove values
  4. pivot table remove values
  5. excel table remove values
  6. remove values from table sql
  7. remove values from table
  8. remove values header pivot table
  9. remove values from table mysql
  10. remove values from table r
  11. remove values from pivot table vba

I'm using Reactabular to create a dynamic table. I've looked everywhere in the source code but couldn't find the CSS file which is responsible for controlling the height and width of the columns. Can ...

I'm using Reactabular to create a dynamic table. I've looked everywhere in the source code but couldn't find the CSS file which is responsible for controlling the height and width of the columns. Can ...

  1. react table change width
  2. react table change column width
  3. react bootstrap table change column width