0
votes

in my vue subscribe-button components, i have mentioned every part props computed and methods. In computed i mentioned the subscribed property: but still it's giving me an error of:-

" [Vue warn]: Property or method "subscribed" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties. "

Subscribe-buttom.js

Vue.component('subscribe-button', {
    props: {
        profile: {
            type: Object,
            required: true,
            default: () => ({})
        },
        subscriptions: {
            type: Array,
            required: true,
            default: () => []
        }
    },
    computed: {
        subscribed: function() {
            if (!__auth() || this.profile.user_id == __auth().id) return false
            return !!this.subscriptions.find(subscription => subscription.user_id == __auth().id)
        }
    },
    methods: {

        toggleSubscription() {
            if (!__auth()) {
                alert('Please login to Subscribe')
            }
        }
    }

})

This is a part of my show.blade.php.

<div class="text-center">
    <subscribe-button :profile="{{ $profile }}" :subscriptions="{{ $profile->subscriptions }}" inline-template>
     <button @click='toggleSubscription' class="btn btn-danger">
      @{{ subscribed ? 'Unsubscribe' : 'Subscribe' }} 7k
     </button>
    </subscribe-button>
  </div>

enter image description here
enter image description here

you are using subscribed outside of your component. Also its a bit strange to have a <button> child for a <subscription-button> component - Flame
Outside of the component!! where? - Rakesh