0

I'm using Laravel together with Vue.js

I got stuck everytime I click removecart button it always return me undefined.

app.js

Vue.component('addtocart', require('./components/AddToCart.vue'));
Vue.component('removecart', require('./components/RemoveCart.vue'));
new Vue({
    el: '#app'
});

RemoveCart.vue

<template>
    <div class="cart-box-item-actions">

        <button @click="removeCart(cartId)" class="button dark-light rmv">
            <!-- SVG PLUS -->
            <svg class="svg-plus">
                <use xlink:href="#svg-plus"></use>
            </svg>
            <!-- /SVG PLUS -->
        </button>
    </div>
</template>

<script>
    import {BASE_URL} from '../bootstrap';

    export default{
        props: ['cartId'],
        methods: {
            removeCart(cartId){
                console.log(cartId);

            }
        }
    }
</script>

cart.blade.php

//Stuffed 
<RemoveCart :cartId="{{ $cart->id }}"></RemoveCart>
// Other stuffed

the console.log always return me undefined. As you can see I have AddToCart component and the code similar to RemoveCart, but it working properly.

Any solution?

4
  • First of all, button element hasn't href attribute. Commented Mar 9, 2017 at 8:05
  • 1
    @Alexandru-IonutMihai thanks for the heads up. I tried <a> and <button> to see if its working or not. but apparently its not. I removed the href. Commented Mar 9, 2017 at 8:05
  • I think your method must be like this: removeCart:function(cartId){ console.log(cartId); } Commented Mar 9, 2017 at 8:07
  • @Alexandru-IonutMihai problem solved. the cartId should be cart-id Commented Mar 9, 2017 at 8:15

1 Answer 1

2

Found the culprit at my view:

Instead of

<RemoveCart :cartId="{{ $cart->id }}"></RemoveCart>

Should be

<RemoveCart :cart-id="{{ $cart->id }}"></RemoveCart>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.