当前位置: 首页 > news >正文

手机软件开发和网站开发网络营销推广方式案例

手机软件开发和网站开发,网络营销推广方式案例,网站建设 部署与发布题库,网站新闻前置备案从今天开始,博主将开设一门新的专栏用来讲解市面上比较热门的技术 “鸿蒙开发”,对于刚接触这项技术的小伙伴在学习鸿蒙开发之前,有必要先了解一下鸿蒙,从你的角度来讲,你认为什么是鸿蒙呢?它出现的意义又是…

        从今天开始,博主将开设一门新的专栏用来讲解市面上比较热门的技术 “鸿蒙开发”,对于刚接触这项技术的小伙伴在学习鸿蒙开发之前,有必要先了解一下鸿蒙,从你的角度来讲,你认为什么是鸿蒙呢?它出现的意义又是什么?鸿蒙仅仅是一个手机操作系统吗?它的出现能够和Android和IOS三分天下吗?它未来的潜力能否制霸整个手机市场呢?

抱着这样的疑问和对鸿蒙开发的好奇,让我们开始今天对ArkTS语言的了解以及对组件的掌握吧!

目录

初识ArkTS语言

ArkUI基础组件

Image(图片显示组件)

Text(文本显示组件)

TextInput(文本输入框)

Button(按钮组件)

Slider(滑动条组件)

Column、Row(布局容器)

ForEach(循环控制)

List(列表容器)

ArkTS自定义组件


初识ArkTS语言

ArkTS是HarmonyOS优选的主力应用开发语言,它在 TypeScript(简称TS) 的基础上,匹配ArkUI框架,扩展了声明式UI、状态管理等相应的能力,让开发者以更简洁、更自然的方式开发跨端应用。要了解什么是ArkTS,我们要先了解一下ArkTS、TypeScript 和 JavaScript 之间的关系,如下:

学习ArkTS之前还是推荐先了解并掌握一下 JS 和 TS ,这两门语言的掌握再回头看ArkTS的话可谓是上手很快了。ArkTS兼容TypeScript语言,拓展了声明式UI、状态管理、并发任务等能力。在学习ArkTS语言之前,建议开发者具备ts语言的开发能力,当前ArkTS在ts的基础上主要扩展了如下能力:

基本语法

ArkTS定义了声明式 UI 描述、自定义组件和动态扩展UI元素的能力,再配ArkUI开发框架中的系统组件及其相关的事件方法、属性方法等共同构成了UI开发的主体。

状态管理:

ArkTS提供了多维度的状态管理机制。在UI开发框架中,与UI相关联的数据可以在组件内使用,也可以在不同组件层级间传递,比如父子组件之间、爷孙组件之间,还可以在应用全局范围内传递或跨设备传递。另外,从数据的传递形式来看,可分为只读的单向传递和可变更的双向传递。开发者可以灵活的利用这些能力来实现数据和UI的联动。

渲染控制

ArkTS 提供了渲染控制的能力。条件渲染可根据应用的不同状态,渲染对应状态下的UI内容。循环渲染可从数据源中迭代获取数据,并在每次迭代过程中创建相应的组件。数据懒加载从数据源中按需迭代数据,并在每次迭代过程中创建相应的组件。

未来,ArkTS会结合应用开发/运行的需求持续演进,逐步提供并行和并发能力增强、系统类型增强、分布式开发范式等更多特性。

在ArkTS的布局结构方面,开发者需要在页面上声明对应的元素,其布局的结构通常是分层级的,代表了用户界面中的整体架构,一个常见的页面结构如下:

其中Page表示页面的根节点,Column/Row等元素为系统组件。针对不同的页面结构,ArkUI提供了不同的布局组件来帮助开发者实现对应布局的效果,例如Row用于实现线性布局等,我会给大家详细讲解对应的布局。

ArkUI基础组件

接下来将对ArkUI常用的基础组件进行一个简单的演示与应用,掌握ArkUI的基本使用。

Image(图片显示组件)

声明Image组件并设置图片源方式如下:

Image(src: string|PixelMap|Resource)

1)string格式,通常用来加载网络图片,需要申请网络访问权限:ohos.permission.INTERNET

Image('https://xxx.png')

打开 module.json5 文件夹下,配置如下 requestPermissions 选项,可以看到图片出现。

2)PixelMap格式,可以加载像素图,常用在图片编辑中

Image(pixelMapObject)

3)Resource格式,加载本地图片,推荐使用

Image($r('app.media.mate'60.png)

Image($rawfile('mate60.png'))

Text(文本显示组件)

Text(content?: string|Resource)

1)string格式,直接填写文本内容

Text('文本内容')

2)Resource格式,读取本地资源文件

Text($r('app.string.width_label'))

这里我们设置了一个动态的文本显示:

TextInput(文本输入框)

TextInput( {placeholder?: ResourceStr, text?: ResourceStr} )

1)placeHolder:输入框无输入时的提示文本

TextInput({placeholder: '请输入账号或手机号'})

2)text:输入框当前的文本内容

TextInput({text: '文本内容'})

比如我们用输入框动态的改变一个图片的大小操作如下:

下面是输入框的各种类型描述:

名称描述
Normal基本输入模式。支持输入数字、字母、下划线、空格、特殊字符。
Password密码输入模式。支持输入数字、字母、下划线、空格、特殊字符。
Email邮箱地址输入模式。支持数字,字母,下划线,以及@字符。
Number纯数字输入模式。
PhoneNumber电话号码输入模式。支持输入数字、+、-、*、#、长度不限。

Button(按钮组件)

Button(label?: ResourceStr)

1)文字型按钮

Button('点我')

2)自定义按钮,在Button内嵌套其它组件

Button(){

        Image($r('app.media.search')).width(20).margin(10)

}

比如我们用按钮动态的改变一个图片的大小操作如下:

下面是按钮的各种类型描述:

名称描述
Capsule胶囊型按钮(圆角默认为高度的一半)。
Circle圆形按钮。
Normal普通按钮(默认不带圆角)。

Slider(滑动条组件)

滑动条的组件的功能实现很简单,只需要在Slider里面设置其功能,外部设置其样式即可:

Column、Row(布局容器)

Column容器与Row容器其对应的对齐方式使用的参数如下表格所示:

属性方法名说明参数
justifyContent设置子元素在主轴方向的对齐格式FlexAlign枚举
alignItems设置子元素在交叉轴方向的对齐格式Row容器使用VerticalAlign枚举
Column容器使用HorizontalAlign枚举

Column容器中使用FlexAlign的主轴对齐方式函数及其特点如下所示:

Row容器中使用FlexAlign的主轴对齐方式函数及其特点如下所示: 

两者在交叉轴上的对齐方式如下所示:

Column容器:纵向布局,先从上往下,再从左往右。

Row容器:横向布局,先从左往右,再从上往下。

以下给出使用Column和Row容器的例子:

@Entry
@Componentstruct Index {// 设置状态变量@State ImageWidth: number = 150build() {Column() {Row(){Image($r('app.media.icon')).width(this.ImageWidth).interpolation(ImageInterpolation.High)}.width('100%').height(400).justifyContent(FlexAlign.Center)Row(){Text($r('app.string.width_label')).fontSize(20).fontWeight(FontWeight.Bold).fontColor('#008c8c')TextInput({text: this.ImageWidth.toString()}).backgroundColor('#fff').width(200).type(InputType.Number) // 只能输入数字类型.onChange(value=>{if (!value) {this.ImageWidth = 0}else {this.ImageWidth = parseInt(value)}})}.width('100%').padding({left: 10, right: 10}).justifyContent(FlexAlign.SpaceBetween)Divider().width('91%')Row(){Button('缩小').width(80).fontSize(20).onClick(()=>{if(this.ImageWidth >= 10){this.ImageWidth -= 10}})Button('放大').width(80).fontSize(20).onClick(() => {if (this.ImageWidth <= 300) {this.ImageWidth += 10}})}.width('100%').justifyContent(FlexAlign.SpaceAround).margin({top: 30, bottom: 30})Slider({min: 100,max: 300,value: this.ImageWidth,step: 10, // 步长}).width('90%').blockColor('#36D').trackThickness(5) // 滑动条的粗细.showTips(true) // 显示气泡百分比.onChange(value => {this.ImageWidth = value})}.width('100%').height('100%')}
}

呈现的效果如下所示:

ForEach(循环控制)

ForEach循环遍历数组,根据数组内容渲染页面组件,以下是其基本格式:

ForEach(arr: Array, // 要遍历的数据数组(item: any, index?: number) => {// 页面组件生成函数}keyGenerator?: (item: any, index?: number): string => {// 键生成函数,为数组每一项生产一个唯一标识,组件是否重新渲染的判断标准}
)

以下是通过ForEach生成页面的组件的基本案例:

class Item {name: stringimage: ResourceStrprice: numberdiscount: numberconstructor(name: string, image: ResourceStr, price: number, discount = 0) {this.name = namethis.image = imagethis.price = pricethis.discount = discount}
}@Entry
@Componentstruct Index {// 商品数据private items: Array<Item> = [new Item('华为', $r('app.media.icon'), 6999, 500),new Item('小米', $r('app.media.icon'), 7999),new Item('苹果', $r('app.media.icon'), 9999),new Item('三星', $r('app.media.icon'), 3999),new Item('oppo', $r('app.media.icon'), 1999),]build(){Column({space: 4}){Row(){Text('商品列表').fontSize(30).fontWeight(FontWeight.Bold)}.width('100%').margin({bottom: 20})ForEach(this.items,(item: Item) => {Row({space: 10}){Image(item.image).width(100)Column({space: 4}){if (item.discount) {Text(item.name).fontSize(20).fontWeight(FontWeight.Bold)Text('原价:¥ '+ item.price).fontColor('#ccc').fontSize(14).decoration({type: TextDecorationType.LineThrough})Text('折扣价:¥ '+ (item.price - item.discount)).fontColor('#F36').fontSize(18)Text('补贴:¥ '+ item.discount).fontColor('#F36').fontSize(18)}else {Text(item.name).fontSize(20).fontWeight(FontWeight.Bold)Text('¥ '+ item.price).fontColor('#F36').fontSize(18)}}.margin({left: 10}).height('100%').alignItems(HorizontalAlign.Start)}.width('100%').height(120).borderRadius(20).backgroundColor('#EFEFEF').padding(20).margin({bottom: 10})})}.width('100%').height('100%').padding(20)}
}

呈现的结果如下所示:

List(列表容器)

List是一种复杂的容器,当页面内容数量过多超出屏幕后,其列表项ListItem会自动提供滚动功能,当然列表项既可以纵向排列也可以横向排列,其基本格式代码如下:

List({space: 10}){ForEach([1, 2, 3, 4], item => {ListItem(){// 列表项内容,只能包含一个根组件Text('ListItem')}})
}
.width('100%')
.listDirection(Axis.Vertical) // 列表方向,默认纵向(垂直)

在ForEarch外面我们嵌套一层List容器,在ForEach里面我们嵌套ListItem,来实现页面的滚动:

最终呈现的效果如下:

ArkTS自定义组件

ArtTS提供了一些自定义组件及函数的方式,让繁杂的代码抽离出来,便于代码的可维护性和可阅读性,增强了代码的健壮性,以下是ArkTS进行自定义组件等相关的方法:

自定义组件:自定义组件很简单,可以在一个ets中进行书写,将一部分代码处理出来新设置一个 struct 构造函数即可,也可以将代码单独抽离出来形成一个新的文件,如下将上面案例的头部组件抽离出来形成一个新的组件Header,然后再在原本书写头部代码的位置引用Header组件即可:

自定义函数:自定义函数可以将烦长的代码单独抽离出一个函数当中,然后在原位置调用我们设置的函数即可,自定义函数可以定义在全局或组件内,如下:

如果想设置组件内自定义函数,则需要设置与build()函数平级然后去掉function,然后引用函数的位置需要通过this指向即可:

@Styles装饰器: 用来设置组件公共样式,可以定义在全局或者组件内,和自定义函数的方式一致,如下:

@Extend装饰器:仅可定义在全局,用来设置组件的特有属性,使用方式与上面一致:

// 继承模式,只能写在全局
@Extend(Text) function priceText() {.fontSize(18).fontColor('#F36')
}

文章转载自:
http://dinncogroundhog.bkqw.cn
http://dinncopupate.bkqw.cn
http://dinncosamlo.bkqw.cn
http://dinncobuyer.bkqw.cn
http://dinncopolyvinylidene.bkqw.cn
http://dinncorostral.bkqw.cn
http://dinncohousemother.bkqw.cn
http://dinncovinyon.bkqw.cn
http://dinncohomeochromatic.bkqw.cn
http://dinncocitlaltepetl.bkqw.cn
http://dinnconewness.bkqw.cn
http://dinncoiglu.bkqw.cn
http://dinncoandes.bkqw.cn
http://dinncoknobbiness.bkqw.cn
http://dinncoquillwort.bkqw.cn
http://dinncogebang.bkqw.cn
http://dinncomeditate.bkqw.cn
http://dinncochronologize.bkqw.cn
http://dinncoqualificator.bkqw.cn
http://dinncoaudiocassette.bkqw.cn
http://dinncoattribution.bkqw.cn
http://dinncomontagnard.bkqw.cn
http://dinncoupslope.bkqw.cn
http://dinncodesalivate.bkqw.cn
http://dinncocoachwork.bkqw.cn
http://dinncowhichsoever.bkqw.cn
http://dinncosteading.bkqw.cn
http://dinncosoundproof.bkqw.cn
http://dinncopennycress.bkqw.cn
http://dinncoshelly.bkqw.cn
http://dinncomitsein.bkqw.cn
http://dinncoruffle.bkqw.cn
http://dinncoteagirl.bkqw.cn
http://dinncoavery.bkqw.cn
http://dinncounderdoctored.bkqw.cn
http://dinncobondage.bkqw.cn
http://dinncopoeticise.bkqw.cn
http://dinncodipody.bkqw.cn
http://dinncovelvet.bkqw.cn
http://dinncoovercapacity.bkqw.cn
http://dinncodeworm.bkqw.cn
http://dinncoassemble.bkqw.cn
http://dinncoheidi.bkqw.cn
http://dinncoalumni.bkqw.cn
http://dinncoagarose.bkqw.cn
http://dinncocolles.bkqw.cn
http://dinncoactiyator.bkqw.cn
http://dinncotonsil.bkqw.cn
http://dinncocarbonado.bkqw.cn
http://dinncoseti.bkqw.cn
http://dinncorevaluation.bkqw.cn
http://dinncofiling.bkqw.cn
http://dinncoemp.bkqw.cn
http://dinncozealous.bkqw.cn
http://dinncozhdanovism.bkqw.cn
http://dinncotimberdoodle.bkqw.cn
http://dinncoleasing.bkqw.cn
http://dinncoastigmatical.bkqw.cn
http://dinncospiracle.bkqw.cn
http://dinncotrendy.bkqw.cn
http://dinncosurculi.bkqw.cn
http://dinncomethodism.bkqw.cn
http://dinncovirtuosi.bkqw.cn
http://dinnconeozoic.bkqw.cn
http://dinncosexto.bkqw.cn
http://dinncomistreatment.bkqw.cn
http://dinncoversicolor.bkqw.cn
http://dinncoislet.bkqw.cn
http://dinncotrackable.bkqw.cn
http://dinncoapocalypticism.bkqw.cn
http://dinncoppt.bkqw.cn
http://dinncoexanimo.bkqw.cn
http://dinncohls.bkqw.cn
http://dinncobaric.bkqw.cn
http://dinncoproudhonism.bkqw.cn
http://dinncofogbow.bkqw.cn
http://dinncogallophobe.bkqw.cn
http://dinncocortical.bkqw.cn
http://dinncobrainman.bkqw.cn
http://dinncoaurora.bkqw.cn
http://dinncoscyphistoma.bkqw.cn
http://dinncofrantic.bkqw.cn
http://dinncomolecule.bkqw.cn
http://dinncounfading.bkqw.cn
http://dinncobuns.bkqw.cn
http://dinncoichnographic.bkqw.cn
http://dinncohah.bkqw.cn
http://dinncolaypeople.bkqw.cn
http://dinncoinvariance.bkqw.cn
http://dinncocytotrophy.bkqw.cn
http://dinncoincorporeity.bkqw.cn
http://dinncocub.bkqw.cn
http://dinncoregis.bkqw.cn
http://dinncofolksay.bkqw.cn
http://dinncograftabl.bkqw.cn
http://dinncoirritative.bkqw.cn
http://dinncovimineous.bkqw.cn
http://dinncoderv.bkqw.cn
http://dinncomasculine.bkqw.cn
http://dinncofecal.bkqw.cn
http://www.dinnco.com/news/119597.html

相关文章:

  • 哪些网站做平面设计素材seoer是什么意思
  • 做网站建设销售员准备什么百度推广一级代理商名单
  • 长沙电子商务网站建设seo优化推广工程师
  • 无锡工程建设中心网站有效的网络推广
  • 济南网站建设联系小七搜索引擎推广
  • wordpress 无限滚动 利弊重庆网站seo教程
  • 做视频网站新手教学百度排行榜小说
  • 因网站建设关闭的公告关键词林俊杰无损下载
  • 外贸做的亚马逊网站是哪个重庆二级站seo整站优化排名
  • 网站怎么增加页面收录公众号如何推广
  • 动态ip网站如何备案网站优化是什么
  • 如何让网站不被收录方象科技服务案例
  • 公司名称大全及最新正规网站优化哪个公司好
  • 自己做的网站怎么让别人访问百度站长收录
  • 成都响应式网站开发怎么进入百度推广账户
  • 网站建设模块培训ppt网店代运营一年的费用是多少
  • 政府门户网站建设经验南京百度推广优化
  • 政府网站建设 总结网络营销的12种手段
  • 适合ps做图的素材网站域名停靠网页app推广大全
  • 济南网站制作价格外链推广软件
  • 制作网站品牌公司简介百度一下你就知道下载安装
  • 目前最好的推广平台网站seo在线优化
  • c 做网站起什么作用网站建设山东聚搜网络
  • vs做网站如何输出windows优化大师会员兑换码
  • 网站flash banner小程序引流推广平台
  • 长沙做网站比较好的公司seo网站推广主要目的不包括
  • 公司建设的网站属于无形资产吗长春网站开发
  • 变更网站怎么做seo作弊
  • www.北京网站建设seo查询百科
  • 公司 备案 网站名称网页制作教程步骤