Use vue-cookies

1, the installation vue-cookies in the project:

npm install vue-cookies --save
or
yarn add vue-cookies --save

  

2, global reference:

// introduced in main.js
 
// require es5 method
var view = require ( 'view')
Vue.use (require ( 'vue-cookies')) // hung on the global
 
 
// es6 method
Import view from 'View'
import VueCookies from 'vue-cookie'
Vue.use (VueCookies) // hung in the global

3, using vue-cookies

  • Set cookie: 
    this.$cookies.set(keyName, keyValue, time)  
  • Get cookie:
    this.$cookies.get(keyName)  
  • Delete cookie:
    this.$cookies.remove(keyName)
  • Detect whether there is a cookie:
    this.$cookies.isKey(keyName)   // 返回true or false  
  • Get all cookie names:
    this.$cookies.keys()
    

      

 

Guess you like

Origin www.cnblogs.com/zaijin-yang/p/12048281.html