[Vuejs]-WP Rest API with vue.js

0👍

This resolved my problem:

    var postLists = Vue.component('post-list',{
       template:'#post-list-template',
       data: function () {
         return {
               posts:'',
          }
        },
     mounted:function () {
          this.$http.get('./wp-json/wp/v2/posts').then(response => {

        // get body data
        this.posts = response.body;

        this.posts.forEach(function (){

        } );

       }, response => {
         console.log('Not Found');
       });
   }


   });

  //router
   var router = new VueRouter({

   routes: [
       { path: '', component: postLists },
      ]
    });

new Vue({
   el: '#app',
   router: router,

    });

Leave a comment