美国云服务器vue引用public的js文件

已关闭留言

美国云服务器具体操作步骤:

1:创建公共JS(utils.js) src/common/utils.js

export default {

text(){

console.log(“测试,测试!!!“)

}

}

2:main.js中引入公共js并注册

import Utils from ‘./common/utils.js’;

Vue.prototype.utils=Utils;

3:调用公共方法

this.utils.text();

相关操作示例:

一个一个方法注册:

1:utils.js

import Vue from ‘vue’

import CryptoJS from ‘crypto-js’

export function encrypt(word, keyStr){//加密

keyStr = keyStr ? keyStr : ‘abcdefgabcdefg12’;

var key = CryptoJS.enc.Utf8.parse(keyStr);//Latin1 w8m31+Yy/Nw6thPsMpO5fg==

var srcs = CryptoJS.enc.Utf8.parse(word);

var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});

return encrypted.toString();

}

export function decrypt(word, keyStr){//解密

keyStr = keyStr ? keyStr : ‘abcdefgabcdefg12’;

var key = CryptoJS.enc.Utf8.parse(keyStr);//Latin1 w8m31+Yy/Nw6thPsMpO5fg==

var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});

return CryptoJS.enc.Utf8.stringify(decrypt).toString();

}

2:main.js中引入并注册

import Utils from ‘./common/utils.js’;

Vue.prototype.$encrypt=encrypt;

Vue.prototype.$decrypt=decrypt;

3:调用

this.$encrypt(“欢迎登录“,”siR6WLQ9pPE0738Y”);

var aa=this.$encrypt(“欢迎登录“,”siR6WLQ9pPE0738Y”);

this.$decrypt(aa,”siR6WLQ9pPE0738Y”);