Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Vuejs's method of deleting cookie

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the method of deleting cookie by vuejs". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "vuejs's method of deleting cookie".

This article operating environment: windows7 system, Vue2.9.6 version, DELL G3 computer.

How does vuejs delete cookie?

Vue.js sets, gets, and deletes cookie

The project needs the front end to obtain the cookie returned by the background and make a judgment based on it. I use it under the main.js entry file.

Specific code:

New Vue ({el:'# app',router,template:', components: {App}, methods: {/ / read cookie). Note that cookie cannot be saved in Chinese. If you need to save Chinese, the solution is to encode encode () at the back end, and then decode it with decodeURI ('string') after it is taken out from the front end. GetCookie (name) {var arr, reg = new RegExp ("(^ |)" + name + "= ([^;] *) (; | $)"); if (arr = [xss_clean] .match (reg)) {return true; / / return (arr [2]) } else {return false}}, / / set cookie name to the name of cookie, value is the value, expiredays is the expiration time (days) setCookie (name, value, expiredays) {var exdate = new Date (); exdate.setDate (exdate.getDate () + expiredays); [xss_clean] = c_name + "=" + escape (value) + (expiredays = = null)? ":"; expires= "+ exdate.toGMTString ()) }, / / Delete cookie delCookie (name) {var exp = new Date (); exp.setTime (exp.getTime ()-1); var cval = getCookie (name); if (cval! = null) [xss_clean] = name + "=" + cval + "; expires=" + exp.toGMTString () }, created () {this.setCookie ('openId',123,2) if (this.getCookie (' openId')) {console.log ('has cookie') this.delCookie (' openId')} else {console.log ('has not cookie')}}) so far, I believe you have a deeper understanding of "vuejs's method of deleting cookie". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report