核心代碼是 getCookie()部分,控制彈框的顯示隱藏則在 created()中。
<template> <div v-if="isShow"> <!--最外層背景--> <div class="popup_container"> <!--居中的容器--> <img @click="noPopup" src="delete.png" alt=""> <!--關閉彈框--> <div class="popup_text"> <!--內容部分--> Lorem ipsum dolor sit amet, consectetur adipisicing elit. At, atque ea eveniet laudantium magni, maiores nam nihil non numquam odio pariatur perferendis placeat quas quasi sit soluta, sunt ullam voluptatibus. </div> </div> </div> </template> <script> export default { data(){ return{ isShow: true, } }, created(){ if (this.getCookie('popped') == ''){ //cookie 中沒有 popped 則賦給他一個值(此時彈框顯示) document.cookie = "popped = yes"; }else{ this.isShow = false; //若cookie 中已經(jīng)有 popped 值,則彈框再不會顯示 } }, methods: { noPopup(){ this.isShow = false; }, getCookie(Name) { //cookie var search = Name + "="; var returnValue = ""; if (document.cookie.length > 0) { var offset = document.cookie.indexOf(search); if (offset !== -1) { offset += search.length; var end = document.cookie.indexOf(";", offset); if (end == -1){ end = document.cookie.length; } returnValue = decodeURIComponent(document.cookie.substring(offset, end)); } } return returnValue; }, }, } </script> <style scoped> /*樣式部分*/ </style>
聲明:本網(wǎng)頁內容旨在傳播知識,若有侵權等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com