plus is not defined
时间: 2023-08-18 15:11:06 浏览: 163
当在浏览器中调试时出现"plus is not defined"的错误提示,这是因为plus是5+Runtime的内部对象,普通浏览器中没有plus环境,只有在HBuilder真机运行、打包后或流应用环境下才能运行plus api。所以在普通浏览器中调用plus api时,控制台会输出"plus is not defined"的错误提示。为了解决这个问题,可以在需要调用plus的地方加上条件编译,使用#ifdef APP-PLUS来限制只在App平台下的代码中调用plus api。另外,还需要确保当前页面引入了mui.js,否则也会出现"mui is not defined"的错误提示。此外,还需要注意在plus和mui完成初始化之前不要调用相关API,可以在plusready的回调事件中调用plus api,确保在初始化完成后再调用。例如:
```
document.addEventListener('plusready', function() {
// 在这里调用plus api
}, false);
```
这样可以避免"plus is not defined"的错误提示。\[1\]\[2\]\[3\]
#### 引用[.reference_title]
- *1* *2* [uni-app真机运行报错:plus is not defined](https://blog.csdn.net/loveliqi/article/details/125737720)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [MUI -- plus初始化原理及plus is not defined,mui is not defined 错误汇总](https://blog.csdn.net/longduyuan/article/details/84805880)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文