How to Fetch data from an External JSON in VueJS

How to Fetch data from an External JSON in VueJS

In this Post We Will Explain About is How to Fetch data from an External JSON in VueJS With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Linking an external JSON file into Vue Example

In this post we will show you Best way to implement javascript – Vue JS – Putting Json on data, hear for Building a JSON Tree View Component in Vue.js from Scratch with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Read Also:  Vuejs Restful Http Post and Get Web Api Calls

Fetching and persisting JSON data using vue.js

In this Example,First of all Add or Inluce External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priorty set.After that Include your relavant CSS Class.

Include External Libs

jquery.min.js
vue.js

index.html

<div id="liveApp">
  <h1>Latest Vue.js Commits</h1>

  <ul>
    <li v-for="cmnt in comments">
      - <span class="message">{{cmnt.commit.message}}</span><br>
      by <span class="author">{{cmnt.commit.author.name}}</span>
      at <span class="date">{{cmnt.commit.author.date}}</span>
    </li>
  </ul>

</div>

index.js

var thirdPartyURL = 'https://api.github.com/repositories/11730342/commits?per_page=5&sha=';

new Vue({

  el: '#liveApp',

  data: {
    currentBranch: 'dev',
    comments: null
  },

  created: function () {
    this.get_Data();
  },

  methods: {
    get_Data: function () {
    var self = this;
    $.get( thirdPartyURL, function( data ) {
        self.comments = data;
        console.log(data);
    });

    }

  }
});

Example 2 : Javascript – vue.js receive json

data.json

{"userName": "Jaydeep Gondaliya"}

index.html:
<div id="liveapp">
    <pre>{{ json.userName }}</pre>
</div>

<script type="text/javascript">
new Vue({
    el: '#liveapp',
    data: {
        json: null
    },
    created: function () {
      fetch("/data.json")
        .then(r => r.json())
        .then(json => {
          this.json=json;
        });
    }
});
</script>

Linking an external JSON file into Vue

Read Also:  Remove Yellow BGBOX WordPress plugin

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is javascript – Vuejs 2 – Passing data from JSON And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.