0
votes

I am trying to show a modal window as in this example. https://codepen.io/anon/pen/dgRKEP?editors=1010 But for some reason, the modal window is not shown.

  <div id="app6">
        <div class="has-text-centered">
            <button class="button is-success" @click="showModal = true">
                show modal!
            </button>
        </div>
        <modal title="Title of the modal" v-show="showModal" @close="showModal = false">
            <div class="content">
                is modal!
            </div>
        </modal>

</div>

Script:

Vue.component('modal', {
  template: `
    <div class="modal is-active">
      <div class="modal-background"></div>
      <div class="modal-content">
        <div class="box"><slot></slot></div>
      </div>
      <button class="modal-close" @click="$emit('close')"></button>
    </div>
  `
});

 new Vue({
        el: '#app6',
        data:{
          ...
            showModal: true
   ...
        },
2

2 Answers

1
votes

I'm assuming you're using Bulma. So you need to include their stylesheet for things to work correctly. The simplest way is to just use a CDN. So you need to include this line in your head tag or somewhere before your app div.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">

Like this for example ..

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">

<div id="app">
  <div id="app" class="container">

    <div class="has-text-centered">
      <button class="button is-success" @click="showModal = true">
        Покажите мне всплывашечку!
      </button>
    </div>

    <modal title="Title of the modal" v-show="showModal" @close="showModal = false">
      <div class="content">

      </div>
    </modal>
  </div>
</div>

See this JSFiddle

1
votes

You need to add the css. you can add your own css or use the library that used in the code pen example: https://cdnjs.cloudflare.com/ajax/libs/bulma/0.2.3/css/bulma.min.css. Clicking the css setting button you will find the imported library.