vue.js實(shí)現(xiàn)只彈一次彈框
更新時(shí)間:2018年01月29日 13:39:53 投稿:laozhang
本篇文章通過代碼實(shí)例給大家詳細(xì)講述了一個(gè)vue的實(shí)例,實(shí)現(xiàn)只彈一次彈框功能,一起學(xué)習(xí)分享下。
核心代碼是 getCookie()部分,控制彈框的顯示隱藏則在 created()中。
<template> <div v-if="isShow"> <!--最外層背景--> <div class="popup_container"> <!--居中的容器--> <img @click="noPopup" src="delete.png" alt=""> <!--關(guān)閉彈框--> <div class="popup_text"> <!--內(nèi)容部分--> 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 則賦給他一個(gè)值(此時(shí)彈框顯示) document.cookie = "popped = yes"; }else{ this.isShow = false; //若cookie 中已經(jīng)有 popped 值,則彈框再不會(huì)顯示 } }, 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>
以上就是這個(gè)功能的代碼實(shí)現(xiàn)內(nèi)容,感謝你對腳本之家的支持。
您可能感興趣的文章:
- js+html5實(shí)現(xiàn)半透明遮罩層彈框效果
- vue.js中toast用法及使用toast彈框的實(shí)例代碼
- js自定義彈框插件的封裝
- 輕松實(shí)現(xiàn)js彈框顯示選項(xiàng)
- js重寫alert事件(避免alert彈框標(biāo)題出現(xiàn)網(wǎng)址)
- js實(shí)現(xiàn)上下左右彈框劃出效果
- 基于layer.js實(shí)現(xiàn)收貨地址彈框選擇然后返回相應(yīng)的地址信息
- javascript實(shí)現(xiàn)無法關(guān)閉的彈框
- JavaScript實(shí)現(xiàn)alert彈框效果
- JavaScript封裝彈框插件的方法
相關(guān)文章
在Vue中使用Avue、配置過程及實(shí)際應(yīng)用小結(jié)
在項(xiàng)目中遇到通過點(diǎn)擊加號實(shí)現(xiàn)輸入框的增加、以及對該輸入框的輸入內(nèi)容進(jìn)行驗(yàn)證,通過這些誘導(dǎo)因素創(chuàng)作的這篇文章,本文重點(diǎn)給大家介紹在Vue中使用Avue、配置過程以及實(shí)際應(yīng)用,需要的朋友可以參考下2022-10-10vue多頁面項(xiàng)目開發(fā)實(shí)戰(zhàn)指南
一般我們的vue項(xiàng)目都是單頁面的,其實(shí)因?yàn)関ue在工程化開發(fā)的時(shí)候依賴了webpack,webpack幫我們將所有的資源整合到一起而形成一個(gè)單頁面,下面這篇文章主要給大家介紹了關(guān)于vue多頁面項(xiàng)目開發(fā)的相關(guān)資料,需要的朋友可以參考下2022-01-01vue3+vite+ts使用monaco-editor編輯器的簡單步驟
因?yàn)楫呍O(shè)需要用到代碼編輯器,根據(jù)調(diào)研,我選擇使用monaco-editor代碼編輯器,下面這篇文章主要給大家介紹了關(guān)于vue3+vite+ts使用monaco-editor編輯器的簡單步驟,需要的朋友可以參考下2023-01-01在vue中對數(shù)組值變化的監(jiān)聽與重新響應(yīng)渲染操作
這篇文章主要介紹了在vue中對數(shù)組值變化的監(jiān)聽與重新響應(yīng)渲染操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07