第一次写代码,想用简单计算器测试一下,结果在模拟器里面运行是空白,但是在预览器里面是可以用的,是怎么回事?有人知道吗




智能客服
你问我答,随时在线为你解决问题
匿名用户第一次写代码,想用简单计算器测试一下,结果在模拟器里面运行是空白,但是在预览器里面是可以用的,是怎么回事?有人知道吗




华夏
很简单,修改一下启动界面是那个一个page就行了:
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Calculator', (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
}
匿名用户
华夏回复匿名用户
丿未来丶问题解决:
首先图1 是预览器不是模拟器,预览器是在一个 struct Calculate 的页面上添加 @Preview 就可以在页面开发工具上预览一个简单的操作。
图3是模拟器,模拟器运行是按照 EntryAbility.ets 文件进行加载页面的,可以在 onWindowStageCreate(windowStage: window.WindowStage) {} 方法进行加载你要的 struct Calculate 页面。如下代码:
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', ' continue Ability onWindowStageCreate');
//这里填写要加载的页面
windowStage.loadContent("pages/Calculate", (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s',
JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
JSON.stringify(data) ?? '');
});
}
匿名用户我要提问题
HarmonyOS 开通地图服务,模拟器地图不显示 (API12+)
现在不能使用模拟器吗?
HarmonyOS 模拟器运行提示“Failed to get the device apiVersion” (API12+)
Qt工程是否能在模拟器或Previewer运行
模拟器预览是不支持物理键盘输入中文吗?
模拟器是不支持录音的功能吗?
推送服务申请成功前能在模拟器上使用吗?
uni-app是否可以在模拟器上运行
智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功