HarmonyOS鸿蒙Next中hello world手表
HarmonyOS鸿蒙Next中hello world手表
第三页旋转图片页代码供大家参考
import router from ‘@system.router’
var picker1value=null; var picker2value=null; var picker1seconds=null; var picker2seconds=null; var timer1=null; var timer2=null; var timer3=null; var counter=null;
export default { data: { seconds:0, isshow:true, huxi:‘breathe in’, percent:“0”, duration:"", count:"" }, clickAction(){ clearInterval(timer1); timer1=null; clearInterval(timer2); timer2=null; clearInterval(timer3); timer3=null; router.replace({ uri:‘pages/index/index’ }); }, run1(){ this.seconds–; if(this.seconds==0){ clearInterval(timer1); timer1=null; this.isshow=false; } }, run2(){ counter++; if (counter == picker1seconds/picker2seconds){ clearInterval(timer2); timer2=null; this.huxi=‘finished’; } else { if (this.huxi==‘breathe in’) { this.huxi =‘breathe out’; } else if (this.huxi==‘breathe out’){ this.huxi=‘breathe in’; } } }, run3(){ this.percent=(parseInt(this.percent)+1).toString(); if(parseInt(this.percent)<10) { this.percent=“0” + this.percent; } if(parseInt(this.percent)==100){ this.percent=“0”; } if (timer2==null){ clearInterval(timer3); timer3=null; this.percent=‘100’; } }, onInit(){ console.log(‘Product onInit() was called’+this.data1); console.log(‘Product onInit() was called’+this.data2);
picker1value=this.data1;
picker2value=this.data2;
if (picker1value=='A.'){
picker1seconds=60;
} else if (picker1value=='B.') {
picker1seconds=120;
} else if (picker1value=="C.") {
picker1seconds=180;
}
if (picker2value=='E.') {
picker2seconds=6;
} else if (picker2value=='F.') {
picker2seconds=3;
}
this.seconds=picker1seconds;
this.duration=picker2seconds+"s";
this.count=(picker1seconds/picker2seconds).toString();
},
onReady(){
console.log('Product onReady() was called');
},
onShow(){
console.log('Product onShow() was called');
timer1 = setInterval(this.run1,1000);
timer2 = setInterval(this.run2,picker2seconds*1000);
timer3 = setInterval(this.run3,picker2seconds/100*1000);
},
onDestroy(){
console.log('Product onDestroy() was called');
}
}
更多关于HarmonyOS鸿蒙Next中hello world手表的实战教程也可以访问 https://www.itying.com/category-93-b0.html
来来来,给博主点赞.....
更多关于HarmonyOS鸿蒙Next中hello world手表的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
厉害,写的太好了…
按照鸿蒙文档“resources/rawfile/icon.png”的路径访问失败,请问该如何设置路径?
手表教学视频中专门在js目录下设置common目录存放资源文件,回避了这个问题
引用方式
通过文件类型(type)和资源名称(name)的组合引用。
Java 文件采用:ResourceTable.*type*_****name*
。特别地,如果引用的是系统资源,则采用:ohos.global.systemres.ResourceTable.*type*_*name*
。
XML 文件采用:$*type*:***name*
。特别地,如果引用的是系统资源,则采用:$ohos:*type*:***name*
。
通过指定文件路径和文件名来引用。
例如:“resources/rawfile/example.js”。
不错,还是相当高明的
一直觉得这内容有内涵
HarmonyOS的社区里有很多技术大牛分享经验,学到了很多有用的知识。
太惭愧了,还是学下好了
随手找的图片,谈不上魔改,js 适合lite wearable,真想魔改必须上java 或c
https://github.com/gudqs7/My-HarmonyOS-First-Demo
啊, 魔改大师, 在下佩服佩服… 特献上原效果代码, 不成敬意!
最近真好在找这个,我需要
在HarmonyOS鸿蒙Next中,创建“Hello World”手表应用涉及以下几个步骤:
-
环境准备:确保已安装DevEco Studio和HarmonyOS SDK。
-
创建项目:打开DevEco Studio,选择“Create Project”,然后选择“Wearable”模板。
-
配置项目:填写项目名称、包名、项目路径等信息,选择API级别和设备类型为“Wearable”。
-
编写代码:在
src/main/js/default/pages/index
目录下,找到index.js
文件。修改index.js
文件,添加以下代码:export default { data: { title: 'Hello World' }, onInit() { this.$page.setTitleBar({ text: 'Hello World' }); } }
-
布局文件:在
src/main/js/default/pages/index
目录下,找到index.hml
文件。修改index.hml
文件,添加以下代码:<div class="container"> <text class="title">{{title}}</text> </div>
-
样式文件:在
src/main/js/default/pages/index
目录下,找到index.css
文件。修改index.css
文件,添加以下代码:.container { flex-direction: column; justify-content: center; align-items: center; height: 100%; } .title { font-size: 30px; color: #000000; }
-
运行项目:连接手表设备或使用模拟器,点击“Run”按钮运行项目。
完成以上步骤后,手表设备或模拟器上将显示“Hello World”文本。
在HarmonyOS鸿蒙Next中开发一个简单的“Hello World”手表应用,可以按照以下步骤进行:
-
创建项目:在DevEco Studio中创建一个新的项目,选择“Wearable”模板。
-
编写代码:在
MainAbilitySlice.java
中,使用Text
组件显示“Hello World”文本。示例代码如下:public class MainAbilitySlice extends AbilitySlice { @Override public void onStart(Intent intent) { super.onStart(intent); Text text = new Text(this); text.setText("Hello World"); text.setTextSize(50); text.setLayoutConfig(new ComponentContainer.LayoutConfig( ComponentContainer.LayoutConfig.MATCH_PARENT, ComponentContainer.LayoutConfig.MATCH_PARENT)); super.setUIContent(text); } }
-
运行应用:连接手表设备或使用模拟器运行应用,查看“Hello World”显示效果。