vendredi 31 juillet 2020

Cannot show modal on button click using vue.js in laravel

I want to simply open modal on button click, i have used below code for that but i'm getting following error when i click button to open it, I'm new to vue.js so not have much idea about it.

app.js:42386 [Vue warn]: Property or method "showModal" 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

created component for modal:

<template>
<transition name="modal">
    <div class="modal-mask">
      <div class="modal-wrapper">
        <div class="modal-container">

          <div class="modal-header">
            <slot name="header">
              default header
            </slot>
          </div>

          <div class="modal-body">
            <slot name="body">
              default body
            </slot>
          </div>

          <div class="modal-footer">
            <slot name="footer">
              default footer
              <button class="modal-default-button" @click="$emit('close')">
                OK
              </button>
            </slot>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>
<script>
  export default {

  }
</script>

Added button code on view to open modal:

 <button id="show-modal" @click="showModal = true">Show Modal</button>
  <modal v-if="showModal" @close="showModal = false">

    <h3 slot="header">custom header</h3>
  </modal>

In app.js:

Vue.component('modal', require('./components/web/Category.vue').default);


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire