在Vue中导入node-machine-id后显示Can't resolve "child_process" 解决方法:
安装webpack(npm install webpack)
在vue.config.js添加如下代码
const { machineId, machineIdSync } = require('node-machine-id') const webpack = require('webpack') module.exports = { configureWebpack: { plugins: [ new webpack.DefinePlugin({ VERSION: JSON.stringify(machineIdSync({original: true})) }) ], } }
let id = machineIdSync({original: true})
3. 在main.js添加
Vue.prototype.$VERSION = VERSION
4. 在组件中通过
this.$VERSION
``` 即可调用id
- 示例