js-cookie expiration time is set to hours

Foreword:

      Cookies are used in the project, js-cookie is very common, but our expiration time, he supports days by default, if we want to change to hours, what should we do, here is how to share

The official entrance of js-cookie

Implementation:

import Cookies form 'js-cookie'

let num = 2 //失效时间是几小时
let time= new Date(new Date().getTime() + num * 60 * 60 * 1000);
Cookies.set(self.loginForm.account, res.data.data, {
    expires: time
});

It ends here!

Guess you like

Origin blog.csdn.net/weixin_44727080/article/details/113728213