3

In my Laravel App, I have a button on Blade template to show/hide a Vue Component. I tried with the following with the help of the following code here. I get following error:

[Vue warn]: Property or method "isShow" 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://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

@extends('layouts.app')
@section('content')
 <button v-on:click="isShow = !isShow">Toggle hide and show</button>
 <site-email  v-if="isShow"></site-email>
@endsection

Component

 <template>
    <div class="label label-info"> {{domain}}'s Email</div>
 <template>

 <script>
  export default {
    data(){
      return {
          isShow : false,
        }
    }
 }
 </script>

I will highly appreciate your help. 

1 Answer 1

2

Vue's reactive data property is Component scope.

You are now accessing isShow outside of the component, so Vue can't access the property.

My suggest: You may insert the button in <site-email> component.

 <template>
    <button v-on:click="isShow = !isShow">Toggle hide and show</button>
    <div v-show="isShow" class="label label-info"> {{domain}}'s Email</div>
 <template>

 <script>
  export default {
    data(){
      return {
          isShow : false,
        }
    }
 }
 </script>

Or, if you don't want to include the button in the component, you have to use a method to communicate between components like "Event bus", ".sync props"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.