vue 中未定义的 CryptoJS

undefined CryptoJS in vue

https://github.com/brix/crypto-js

我已经使用 npm i crypto-js 安装了 cryptoJs

但我如何在我的项目中使用它? 当我写这段代码时

// Decrypt
var bytes  = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');

var originalText = bytes.toString(CryptoJS.enc.Utf8);

console.log(originalText); 

但它显示一个错误说 CryptoJS 未定义

这是我的代码

<script>
import CryptoJS from 'crypto-js'
require('crypto-js')

export default {
  name: "AnswerQuestionnaire",
  components:{
  
  },
  props: {
  
  },
  data() {
    return {
     
    }
  },

  created(){
    this.CryptoJS.AES.decrypt("zU5jEPwQSm2P0X33jgH6sg==", "sB7b5q4fp0G59R9t").toString(this.CryptoJS.enc.Utf8)
      
  },
  mounted(){
    
  }
};

这是错误

VM820424:1 Uncaught ReferenceError: CryptoJs is not defined
    at eval (eval at created

您必须先导入或要求加密

<script>
import CryptoJS from 'crypto-js';
export default {
  created() {
    var bytes  = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');

    var originalText = bytes.toString(CryptoJS.enc.Utf8);

    console.log(originalText); 
  }
}

</script>