作為一個前端程序員,最喜歡的就是搬代碼,號稱 ctrl+c +v 戰士,那么怎么防止別人盜取自己的代碼保護自己和公司權益呢?我們可以給計算機授權。那么怎樣讓自己的客戶資產使用,讓搬運工無路可走呢??我們可以對啟動服務的服務器進行單獨授權,獲取服務器的獨一無二ID 並使用RSA加密/解密 關於rsa加密可以在我另外一章看,這章講前端怎么獲取 machine-id
1,引入 node-machine-id
cnpm install node-machine-id
在 vue.config.js 文件中 引入 node-machine-id 如果沒有vue.config.js。則自己在根目錄下新建一個。
const { machineId, machineIdSync } = require('node-machine-id')
module.exports = {
configureWebpack: {
plugins: [
new webpack.DefinePlugin({
VERSION: JSON.stringify(machineIdSync({original: true}))
})
],
}
}
machineIdSync 的配置
let id = machineIdSync() // id = c24b0fe51856497eebb6xxxxxxxxxxxxxxxx34d670bb92e09a00ce8169365 // original:如果為true,則返回計算機ID的原始值,否則返回哈希值(sha-256) let id = machineIdSync({original: true}) // id = 989xxx84-xxxx-5xx-8xx-0388xxxx5e4
2,在main.js中賦予全局
Vue.prototype.$VERSION = VERSION
3,在vue組件中使用
即可正常使用啦!!!!!!!!!!