M
M
Muslim Yakhyaev2020-10-29 20:47:21
Vue.js
Muslim Yakhyaev, 2020-10-29 20:47:21

VueJs How to call a modal window once a day?

Good afternoon)
Help please. How to make the modal window pop up when loading the site once a day.

<div v-if="isShow">
        <div class="modal-mask" >
          <div class="modal-wrapper">
            <div class="modal-container">
              <div class="modal-body">
                <slot name="body">
                  <img src="./assets/image/picture.jpg" alt="">
                </slot>
              </div>
              <div class="modal-footer">    
                <slot name="footer">
                  <button class="modal-default-button" @click="close">  Кнопка 1</button>
                  <button class="modal-default-link" @click="close">Кнопка 2</button >
                </slot>
              </div>
            </div>
          </div>
        </div>
  </div>


<script>
export default {
  name: 'app',
  data() {
    return {
      isShow:  true,
    }
  },
  mounted () {
    this.runModalTimer()
    this.setDevHoursModal()
  },
  methods: {
    close(){
      this.isShow = false;
    },
    runModalTimer () {
      setTimeout(() => {
        this.isShow = true
      }, 4000)
    },
    setDevHoursModal() {
      if (localStorage) {
        let nextPopup = localStorage.getItem('isShow');
        if (nextPopup > new Date()) {
          return (this.isShow = true);  // let's be a little more explicit here
        }
        let expires = new Date();
        expires = expires.setHours(expires.getHours() + 24);
        localStorage.setItem('isShow', expires);
        return false;
      }
      return true;
    }
  }
}
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2020-10-29
@wapster92

Save the time of the last launch in localStorage, check with the current one, if more than 24 hours have passed since the last time, then launch the window opening function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question