有没有办法以编程方式确定您是在模拟器中还是在设备上?

Is there a way to determine when you are in the simulator or on device programmatically?

我正在寻找一种方法来以编程方式区分 Vodapay 迷你程序的设备和模拟器,有人知道这样做的方法吗?

谢谢

您可以利用 process.env.NODE_ENV 来实现这一点。在模拟器中 returns 'development' 在设备上 'production'

if (process.env.NODE_ENV ==='development') {
  //run this in simulator
  console.log('simulator');
}
else{
  // run this on device
  console.log('device');
}