在开始之前,请确保您已安装以下工具:
创建完成后,您会看到如下项目结构:
YourProject/
├── src/
│ ├── main/
│ │ ├── js/
│ │ ├── resources/
│ │ ├── ...
│ └── ...
└── ...
config.json
在 src/main/config.json
中配置应用基本信息:
{
"app": {
"id": "com.example.harmonyapp",
"name": "HarmonyApp",
"version": "1.0.0",
"description": "A sample HarmonyOS application"
}
}
在 src/main/js
文件夹中,创建一个 main.js
文件,并添加以下代码:
import app from '@system.app';
import router from '@system.router';
export default {
data: {
title: 'Hello, HarmonyOS!'
},
onInit() {
console.log('Application initialized');
},
navigateToPage() {
router.push({
uri: 'pages/secondPage/secondPage'
});
}
};
在 src/main/resources
中,创建一个 main.hml
文件,并添加以下代码:
<?xml version="1.0" encoding="utf-8"?>
<template>
<div>
<h1>{{ title }}</h1>
<button @click="navigateToPage">Go to Second Page</button>
</div>
</template>
在 src/main/js
文件夹中,创建 secondPage.js
文件:
export default {
data: {
message: 'Welcome to the second page!'
}
};
在 src/main/resources
中,创建 secondPage.hml
文件:
<?xml version="1.0" encoding="utf-8"?>
<template>
<div>
<h1>{{ message }}</h1>
<button @click="goBack">Go Back</button>
</div>
</template>
<script>
export default {
methods: {
goBack() {
const router = require('@system.router');
router.back();
}
}
}
</script>
在 DevEco Studio 中,选择您的设备(如模拟器或实际鸿蒙设备),然后点击“运行”按钮。您的应用程序将被编译并部署到选定的设备上。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。