1.安装crypto-js

npm install  crypto-js -s

2.cryptoJs,自定义加密和解密方法方式

mport CryptoJS from 'crypto-js/crypto-js'
 
/**
* 由后端提供
*/
const KEY = CryptoJS.enc.Utf8.parse('aaDJL2d9DfhLZO0z');// 密钥
const IV = CryptoJS.enc.Utf8.parse('412ADDSSFA342442');// 偏移量  
/**
 * AES加密(字符串,KEY,IV)
 */
export function Encrypt(word, keyStr, ivStr) {
  let key = KEY;
  let iv = IV;
 
  if (keyStr) {
    key = CryptoJS.enc.Utf8.parse(keyStr);
    iv = CryptoJS.enc.Utf8.parse(ivStr);
  }
 
  let srcs = CryptoJS.enc.Utf8.parse(word);
  var encrypted = CryptoJS.AES.encrypt(srcs, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.ZeroPadding
  });
 
  return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
 
}
/**
* AES解密(字符串,KEY,IV)
*/
export function Decrypt(word, keyStr, ivStr) {
  let key  = KEY;
  let iv = IV;
 
  if (keyStr) {
    key = CryptoJS.enc.Utf8.parse(keyStr);
    iv = CryptoJS.enc.Utf8.parse(ivStr);
  }
 
  let base64 = CryptoJS.enc.Base64.parse(word);
  let src = CryptoJS.enc.Base64.stringify(base64);
 
  var decrypt = CryptoJS.AES.decrypt(src, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.ZeroPadding
  });
 
  var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  return decryptedStr.toString();
}

Q.E.D.