HarmonyOS4.0系列——02、汉化插件、声明式开发范式ArkTS和类web开发范式

编辑器调整

我们在每次退出编辑器后再次打开会直接进入项目文件中,这样在新建项目用起来很是不方便,所以这里跟着设置一下就好



这样下次进入就不会直接跳转到当时的文件项目中!!

关于汉化

settingsplugins installed → 输入 chinese → 点击 ebable → 点击 apply →重启DevEco-Studio完成汉化

ArkTS路由

ArkTS的路由在main_pages.json

点击事件

点击事件的写法为

js 复制代码
标签('标签名称')
	.onClick(()=>{
		router.pushUrl({
			url:'路径'
		})
	})

从First.ets跳转到Second.ets页面代码示例:

First.ets
ts 复制代码
import router from '@ohos.router'
@Entry
@Component
struct First {

  build() {
      Column() {
        Text('Southern Wind01')
          .fontSize(30)

        Button('click....')
          .width('40%')
          .height('40vp')
          .margin(20)
          .onClick(()=>{
          //    去第二个页面
            router.pushUrl({
              url:'pages/Second'
            })
          })
      }
    .width('100%')
    .height('100%')
  }
}

Second.ets

js 复制代码
import router from '@ohos.router'
@Entry
@Component
struct second {

  build() {

      Column() {
        Text('Southern Wind02')
          .fontSize(30)
        Button('back')
          .padding(20)
          .margin(20)
          .backgroundColor('#e0e0e0')
          .fontColor('#000')
          .onClick(()=>{
            router.back()
          })
      }
      .width('100%')

    .height('100%')
  }
}

实际效果:

类web开发范式

也就是所谓的前端开发方式。创建时使用FA模型,语言选择JS

类web路由配置

路由页面在config.json

写法和Vue类似

这里看一下
first.html

html 复制代码
<div class="container">
  <text class="title">
    Southern Wind 01
  </text>

  <button @click="goSecond">点击跳转</button>
</div>

first.js

js 复制代码
import router from '@ohos.router'
export default {
  data: {
    title: ""
  },
  onInit() {
    this.title = "Southern Wind";

  },
  //   跳转事件
  goSecond(){
    // router.pushUrl({
    //   url:'pages/second/second'
    // })
    router.push({
      url:'pages/second/second'
    })
  }
}

注意:这里官方是说9版本以后使用pushUrl,但在js写法中起不了作用,应该是还没兼容导致的,这里还是用老版的router.push即可

second.html

html 复制代码
<div class="container">
  <text class="title">
    Southern Wind 02
  </text>
  <button @click="back">back</button>
</div>

second.js

js 复制代码
import router from '@ohos.router'
export default {
  data: {
    title: ""
  },
  onInit() {
  },
  back(){
    router.back();
  }
}

效果:

相关推荐
世人万千丶4 分钟前
解决鸿蒙方向的Flutter框架版切换问题-当前最新版本3.35.8——工具切换与命令切换
学习·flutter·elasticsearch·华为·harmonyos·鸿蒙
亿元程序员10 分钟前
Cocos4开源都快半年了,还有不会用官方MCP的?安排!
前端
亘元有量-流量变现1 小时前
鸿蒙、安卓、苹果音频设备技术深度解析与开发实践
android·wpf·harmonyos·亘元有量·积分墙
奔跑的呱呱牛1 小时前
xlsx 已停止维护且存在漏洞!推荐一个可直接替代的 npm 库
前端·npm·node.js·xlsx·sheetjs
珑墨1 小时前
pnpm 与 node_modules:硬链接、软连接(符号链接)、Junction 速记
前端
freewlt1 小时前
Monorepo 架构下的前端工程化实践:pnpm + Turborepo 从入门到落地
前端·arcgis·架构
徐小夕9 小时前
我用 AI 撸了个开源"万能预览器":浏览器直接打开 Office、CAD 和 3D 模型
前端·vue.js·github
小码哥_常9 小时前
Flutter Android 延迟加载代码指南:提升应用性能的关键
前端
这是个栗子10 小时前
TypeScript(三)
前端·javascript·typescript·react
kvo7f2JTy10 小时前
基于机器学习算法的web入侵检测系统设计与实现
前端·算法·机器学习