利用localStorage让首页弹框只在页面出现一次

    
    <div v-if="isShow">
        
        <div class="opacity-back">div>
        
        <div class="model-box">
            <div class="model-header">
                <span class="close" @click="close">×span>
            div>
            <div class="model-body">
                <a :href="plaqueObj.webClickUrl" target="_blank"><img :src="plaqueObj.picUrl" alt="">a>
            div>
        div>
    div>
<script>
  export default {
    data() {
      return {
        isShow: false,
        plaqueObj: {}
      }
    },
    created(){
      var that = this
      that.haha()
    },
    methods: {
      close() {
        localStorage.setItem('look', 'false')
        this.isShow = false
      },
      async haha() {
        const res = await this.getPlaque()
        console.log(res)
        if (res.data.list.length !== 0) {
          if (localStorage.getItem('look') !== null) {
            this.isShow = false
          } else {
            this.isShow = true
            this.plaqueObj = res.data.list[0]
          }
        } else {
          this.isShow = false
        }
      },
      getPlaque() {
        let urlParams = {
          status: 1,
          pageNum: 1,
          pageSize: 1,
          type: 1
        }
        return new Promise((resolve, reject) => {
        this.$utils.getJson(this.$utils.CONFIG.api.plaqueList, function (res) {
          resolve(res)
        }, function (error) {
          reject(error)
        }, {}, false, urlParams, 'get',{})
      })
      }
    }
  }
</script>

你可能感兴趣的:(vue,vue)