mercredi 7 mars 2018

Uncaught TypeError: axios.ad is not a function in vue script

I'm having this error with my vue script, this are the files i'm using Can't find the error reported with the axios.ad (favoriteAd.vue). It's basically a favourite feature using: https://scotch.io/tutorials/implement-a-favoriting-feature-using-laravel-and-vue-js#comments-section (replacing post with ad)

app.js

require('./bootstrap');

window.Vue = require('vue');

Vue.component('favorite', require('./components/FavoriteAd.vue'));

const app = new Vue({
  el: '#favorite'
});

favoriteAd.vue

 <template>
<span>
    <a href="#" v-if="isFavorited" @click.prevent="unFavorite(ad)">
        <i  class="fa fa-heart"></i>
    </a>
    <a href="#" v-else @click.prevent="favorite(ad)">
        <i  class="fa fa-heart-o"></i>
    </a>
</span>
</template>

<script>
export default {
    props: ['ad', 'favorited'],

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

    mounted() {
        this.isFavorited = this.isFavorite ? true : false;
    },

    computed: {
        isFavorite() {
            return this.favorited;
        },
    },

    methods: {
        favorite(ad) {
            console.log(ad);
            axios.ad('/favorite/'+ad) // this is the error line
                .then(response => this.isFavorited = true)
                .catch(response => console.log(response.data));
        },

        unFavorite(ad) {
            axios.ad('/unfavorite/'+ad)
                .then(response => this.isFavorited = false)
                .catch(response => console.log(response.data));
        }
    }
}

view

@if (Auth::check())
 <favorite
    :ad=
    :favorited=
></favorite>   
@endif



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2Fnmkgl
via IFTTT

Aucun commentaire:

Enregistrer un commentaire