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

外贸网站制作要求百度网络营销中心

外贸网站制作要求,百度网络营销中心,wordpress 免费插件,wordpress 卡通插件一、前言 Require是校验Prop、State、Provide、BuilderParam和普通变量(无状态装饰器修饰的变量)是否需要构造传参的一个装饰器。 说明 从API version 11开始对Prop/BuilderParam进行校验。 从API version 11开始,该装饰器支持在元服务中使用。 从API version 12开…

一、前言

@Require是校验@Prop、@State、@Provide、@BuilderParam和普通变量(无状态装饰器修饰的变量)是否需要构造传参的一个装饰器。

说明
从API version 11开始对@Prop/@BuilderParam进行校验。
从API version 11开始,该装饰器支持在元服务中使用。
从API version 12开始对@State/@Provide/普通变量(无状态装饰器修饰的变量)进行校验。

二、概述

当@Require装饰器和@Prop、@State、@Provide、@BuilderParam、普通变量(无状态装饰器修饰的变量)结合使用时,在构造该自定义组件时,@Prop、@State、@Provide、@BuilderParam和普通变量(无状态装饰器修饰的变量)必须在构造时传参。

三、限制条件

@Require装饰器仅用于装饰struct内的@Prop、@State、@Provide、@BuilderParam和普通变量(无状态装饰器修饰的变量)。

四、使用场景

当Child组件内使用@Require装饰器和@Prop、@State、@Provide、@BuilderParam和普通变量(无状态装饰器修饰的变量)结合使用时,父组件TestRequire在构造Child时必须传参,否则编译不通过。

TestRequire.ets代码

@Entry
@Component
struct TestRequire {@State message: string = 'Hello World';@BuilderbuildTest() {Row() {Text('Hello, world').fontSize(20)}}build() {Row() {Child({regular_value: this.message,state_value: this.message,provide_value: this.message,initMessage: this.message,message: this.message,buildTest: this.buildTest,initBuildTest: this.buildTest})}.margin({ top: 30 })}
}@Component
struct Child {@BuilderbuildFunction() {Column() {Text('initBuilderParam').fontSize(20)}}@Require regular_value: string = 'Hello';@Require @State state_value: string = "Hello";@Require @Provide provide_value: string = "Hello";@Require @BuilderParam buildTest: () => void;@Require @BuilderParam initBuildTest: () => void = this.buildFunction;@Require @Prop initMessage: string = 'Hello';@Require @Prop message: string;build() {Column() {Text(this.initMessage).fontSize(30)Text(this.message).fontSize(30)this.initBuildTest();this.buildTest();}.width('100%').height('100%')}
}

效果图

在这里插入图片描述

使用@ComponentV2修饰的自定义组件ChildPage通过父组件ParentPage进行初始化,因为有@Require装饰,所以父组件必须进行构造赋值。

@ObservedV2
class Info {@Trace name: string = '';@Trace age: number = 0;
}@ComponentV2
struct ChildPage {@Require @Param childInfo: Info = new Info();@Require @Param state_value: string = "Hello";build() {Column() {Text(`ChildPage childInfo name :${this.childInfo.name}`).fontSize(20).fontWeight(FontWeight.Bold)Text(`ChildPage childInfo age :${this.childInfo.age}`).fontSize(20).fontWeight(FontWeight.Bold)Text(`ChildPage state_value age :${this.state_value}`).fontSize(20).fontWeight(FontWeight.Bold)}}
}@Entry
@ComponentV2
struct ParentPage {info1: Info = { name: "Tom", age: 25 };label1: string = "Hello World";@Local info2: Info = { name: "Tom", age: 25 };@Local label2: string = "Hello World";build() {Column() {Text(`info1: ${this.info1.name}  ${this.info1.age}`) // Text1.fontSize(30).fontWeight(FontWeight.Bold)ChildPage({ childInfo: this.info1, state_value: this.label1}) // 调用自定义组件Line().width('100%').height(5).backgroundColor('#000000').margin(10)Text(`info2: ${this.info2.name}  ${this.info2.age}`) // Text2.fontSize(30).fontWeight(FontWeight.Bold)ChildPage({ childInfo: this.info2, state_value: this.label2}) // 调用自定义组件Line().width('100%').height(5).backgroundColor('#000000').margin(10)Button("change info1&info2").onClick(() => {this.info1 = { name: "Cat", age: 18} // Text1不会刷新,原因是没有装饰器修饰监听不到值的改变。this.info2 = { name: "Cat", age: 18} // Text2会刷新,原因是有装饰器修饰,可以监听到值的改变。this.label1 = "Luck"; // 不会刷新,原因是没有装饰器修饰监听不到值的改变。this.label2 = "Luck"; // 会刷新,原因是有装饰器修饰,可以监听到值的改变。})}}
}

效果图

在这里插入图片描述

五、错误场景

@Entry
@Component
struct Index {@State message: string = 'Hello World';@Builder buildTest() {Row() {Text('Hello, world').fontSize(30)}}build() {Row() {Child()}}
}@Component
struct Child {@Builder buildFunction() {Column() {Text('initBuilderParam').fontSize(30)}}// 使用@Require必须构造时传参。@Require regular_value: string = 'Hello';@Require @State state_value: string = "Hello";@Require @Provide provide_value: string = "Hello";@Require @BuilderParam initBuildTest: () => void = this.buildFunction;@Require @Prop initMessage: string = 'Hello';build() {Column() {Text(this.initMessage).fontSize(30)this.initBuildTest();}}
}
http://www.mmbaike.com/news/27698.html

相关文章:

  • 网站开发使用的语言有哪些搜索引擎优化网页
  • 公众号申请嘉兴网站建设方案优化
  • 网站建设教程答允苏州久远网络重庆森林在线观看
  • 宜城做网站软文网站大全
  • 公司的官方网站怎么做想要导航推广网页怎么做
  • 无锡网站建设制作seo推广软件
  • iis7如何搭建网站广州中小企业seo推广运营
  • 网站目录怎么做陕西百度代理公司
  • 电商网站技术方案seo北京
  • WordPress网站hym地图推广的十种方式
  • 网址推广怎么推广厦门搜索引擎优化
  • 南京门户网站制作怎么优化网站关键词的方法
  • 下载类网站如何做想卖产品怎么推广宣传
  • b2c商城网站合同服装品牌策划及营销推广方案
  • 大连网络建站公司分析浙江百度代理公司
  • 用vs2010做购物网站seo排名优化工具
  • 网站开发设计论文百度问答平台入口
  • 网站管理规定太原seo团队
  • 做个网站多少钱怎么接广告广告软文怎么写
  • 动态网站怎么做seo排名点击软件推荐
  • 网站建设文化信息百度推广怎么优化关键词的质量
  • 帆软网站开发衡阳百度推广
  • 个人档案网站该怎么做海门网站建设
  • 建站教程流程图前端seo搜索引擎优化
  • 如何做网站二级域名网上如何推广自己的产品
  • 网站美工建设意见关键词调价工具哪个好
  • 互助盘网站怎么做的网站怎么做优化排名
  • 聊城市城乡建设委员会网站网站之家查询
  • 网站上怎么做福彩卖家上海网络营销seo
  • 定制网站建设公司哪家好网络营销的产品策略