Vue入门(十)Vue常用插件


1cookie操作插件

js-cookie   安装命令: npm install --save js-cookie

*.vue js中使用

 

import Cookies from "js-cookie";

 

// 设置token , 过期时间 30

Cookies.set("username", this.loginForm.username, { expires: 30 });

 

// 删除token

Cookies.remove("username");

 

// 获取token

let username = Cookies.get("username)

 

 

2、JSEncrypt (RSA)

 

  安装命令: npm install --save jsencrypt/bin/jsencrypt    

 

// jsencrypt.js 

 

import JSEncrypt from 'jsencrypt/bin/jsencrypt'

 

// 密钥对生成 http://web.chacuo.net/netrsakeypair

 

const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD\n' +

  '2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ=='

 

const privateKey = 'MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8\n' +

  'mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9p\n' +

  'B6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue\n' +

  '/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZ\n' +

  'UBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6\n' +

  'vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha\n' +

  '4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3\n' +

  'tTbklZkD2A=='

 

// 加密

export function encrypt(txt) {

  const encryptor = new JSEncrypt()

  encryptor.setPublicKey(publicKey) // 设置公钥

  return encryptor.encrypt(txt) // 对需要加密的数据进行加密

}

 

// 解密

export function decrypt(txt) {

  const encryptor = new JSEncrypt()

  encryptor.setPrivateKey(privateKey)

  return encryptor.decrypt(txt)

}

 

import { encrypt, decrypt } from '@/utils/jsencrypt'

 

Let passwd = encrypt(this.loginForm.password) ;

 

Let passwd = decrypt(this.loginForm.password) ;




vue

2020.11.18 00:10

https://www.meihaocloud.com.com/378.html , 欢迎转载,请在文章页标出原文连接 !


Copyright © 2020 千夕网 联系站长

粤公网安备 44030302001408号 粤ICP备19099833号-1