Vue-resource: Help with passing WordPress Basic Auth

Created on 4 Oct 2016  路  2Comments  路  Source: pagekit/vue-resource

Need help with passing WordPress Basic Auth to allow for CRUD operations on posts. I have successfully coded the GET call using vue-resource. But of course, when I try to delete a post I get the 401 Unauthorized error in console.

I have googled and tried many different ways to pass my headers without success.

I am running vue js version: Vue.js v1.0.28
Vue resource version: vue-resource v0.9.3

I have attached a screen shot of my console error:

here is some of my code:

<script type="text/javascript">
        Vue.http.headers.common['Authorization'] = 'Basic ZHhsYWRuZXI6cGFzc3dvcmQ';
        var apiURL = 'http://localhost/wpdev/wp-json/wp/v2/book/';

        new Vue({
            el: '#demoList',

            data: function() {
                return {
                  wpPosts: ''
                }
            },

            ready: function () {
                this.fetchPosts();
            },

            methods: {
                fetchPosts: function () {
                  this.$http.get(apiURL).then((response) => {
                    this.$set('wpPosts', response.data)
                  })
                },

                deletePost: function(id) {
                    var ConfirmBox = confirm('Are you sure you want to delete this post '+ id)

                    if(ConfirmBox) this.$http.delete(apiURL + id)

                    this.fetchPosts()

                },
            }
        });

    </script>

screen shot 2016-10-04 at 9 04 35 am

All 2 comments

Anyone help please????

with the lack of support I have abandoned Vue in lue of React. . This is how projects like Vue JS does not grow at a good rate and gets left behind.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

facesea picture facesea  路  5Comments

EmilMoe picture EmilMoe  路  5Comments

yozman picture yozman  路  6Comments

nivv picture nivv  路  4Comments

Dreampie picture Dreampie  路  3Comments