How can I set a cookie in react?

后端 未结 7 2241
忘了有多久
忘了有多久 2020-11-30 20:09

Orginally, I use the following ajax to set cookie.

function setCookieAjax(){
  $.ajax({
    url: `${Web_Servlet}/setCookie`,
    contentType: \'application/         


        
7条回答
  •  一生所求
    2020-11-30 20:39

    It appears that the functionality previously present in the react-cookie npm package has been moved to universal-cookie. The relevant example from the universal-cookie repository now is:

    import Cookies from 'universal-cookie';
    const cookies = new Cookies();
    cookies.set('myCat', 'Pacman', { path: '/' });
    console.log(cookies.get('myCat')); // Pacman
    

提交回复
热议问题