手机网站被拦截怎么办怎么解决,网站内容创造,西安网站建设选任我行网络,wordpress获取上传路径【关键字】
服务卡片、卡片跳转不同页面、卡片跳转页面携带参数 【写在前面】 本篇文章主要介绍开发服务卡片时#xff0c;如何实现卡片点击跳转不同页面#xff0c;并携带动态参数到js页面。在此篇文章“服务卡片 API6 JSUI跳转不同页面”中说明了如果跳转不同页面#xf… 【关键字】
服务卡片、卡片跳转不同页面、卡片跳转页面携带参数 【写在前面】 本篇文章主要介绍开发服务卡片时如何实现卡片点击跳转不同页面并携带动态参数到js页面。在此篇文章“服务卡片 API6 JSUI跳转不同页面”中说明了如果跳转不同页面这里在此基础上介绍跳转js页面时如何携带参数到js页面中。 【开发步骤】
第一步参考下方新建PageAbility继承AceAbility在java目录下新建类型为Page的Ability如下
在config.json中ability字段中对新增的PageAbility配置如下
{name: com.example.routeram.PageAbility,icon: $media:icon,description: $string:pageability_description,label: $string:entry_PageAbility,type: page,launchType: standard
}
第二步在卡片的json文件中设置router事件跳转到PageAbility中参数中增加了一个type字段后续可以通过type字段判断是跳转到哪个js page中并定义title字段将值设置为data中定义的动态参数可以将其传到js page中。
{data: {detailTitle: i am detail title,mineTitle: i am mine title},actions: {detailRouterEvent: {action: router,bundleName: com.example.routeram,abilityName: com.example.routeram.PageAbility,params: {type: detail,title: {{detailType}}}},mineRouterEvent: {action: router,bundleName: com.example.routeram,abilityName: com.example.routeram.PageAbility,params: {type: mine,title: {{mineTitle}}}}}
}
同时在index.json同级目录index.html文件中绑定mineRouterEvent和detailRouterEvent事件如下所示
text classtitle onclickdetailRouterEvent跳转detail/text
text classtitle onclickmineRouterEvent跳转mine/text
第三步在PageAbility的onStart方法中接收router 传过来的paramsJSON格式获取type字段进行跳转获取title字段通过setPageParams方法传入到js page中。 Overridepublic void onStart(Intent intent) {IntentParams params intent.getParams();if (params ! null) {//获取routerEvent中的paramsString data (String) params.getParam(params);if (!data.isEmpty()) {// 通过ZSONObject获取对应的type的值ZSONObject zsonObject ZSONObject.stringToZSON(data);String type zsonObject.getString(type);// 通过ZSONObject获取对应的title的值,并构造intentParams便于传入到js page中String title zsonObject.getString(title);IntentParams intentParams new IntentParams();intentParams.setParam(title, title);// setInstanceName对应的是Component Name一般我们把Js Page放在默认的default目录下因此这边填写的是defaultsetInstanceName(default);// 跳转不同页面if (type.equals(detail)) {// 不需要传入参数写法setPageParams(pages/detail/detail, null);// 可直接将卡片index.json中定义的参数直接透传到js page中setPageParams(pages/detail/detail, params);// 此处将上面重新定义的intentParams传入js page中setPageParams(pages/detail/detail, intentParams);} else if (type.equals(mine)) {setPageParams(pages/mine/mine, intentParams);}}HiLog.info(TAG, IntentParams: data);}super.onStart(intent);}
第四步在detail.js和mine.js的data中定义相同名称的变量此处定义title即可接受到pageAbility中传入的title数据。 data: {title: ,},onInit() {// 打印获取的title并在index.html显示title值console.info(title is this.title)} 【最终效果】 【服务卡片开发相关文档】
3.0服务卡片开发指导包含基于JS UI和Java UI开发卡片https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ability-service-widget-overview-0000001062607955
3.0Java服务卡片JS UI组件https://developer.harmonyos.com/cn/docs/documentation/doc-references/js-service-widget-file-0000001153028529
3.1/4.0FA模型服务卡片开发指导https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/widget-development-fa-0000001427902244-V3
3.1/4.0Stage模型服务卡片开发指导https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/service-widget-overview-0000001536226057-V3