赞
踩
// 路由
import router from '@system.router';
// 跳转页
router.push ({
uri: 'pages/detail/detail',
params:{} // 参数
});
// 返回上一步
router.back();
import storage from '@system.storage'; // storage.get // storage.set // storage.clear // 清理全部 // storage.delete // storage.xxx({ key: 'storage_key', // get | set | delete default :'', // get value :'', // set success: function(data) { console.log('call storage.get success: ' + data); }, fail: function(data, code) { console.log('call storage.get fail, code: ' + code + ', data: ' + data); }, complete: function() { console.log('call complete'); }, });
import prompt from '@system.prompt'; // 文本提示 prompt.showToast({ message: 'Message Info', // 展示内容 duration: 2000, // 显示时间 默认 1.5 秒 bottom: 100 // 弹框距离屏幕底部距离 }); // 对话框 prompt.showDialog({ title: 'Title Info', // 标题 message: 'Message Info', // 文本 buttons: [ { text: 'button', // 按钮文本 color: '#666666', // 按钮颜色 }, ], success: function(data) { // 成功 data.index 按钮索引 console.log('dialog success callback,click button : ' + data.index); }, cancel: function() { // 取消 console.log('dialog cancel callback'); }, });
需要在config.json 声明 ohos.permission.INTERNET 权限
import request from '@system.request'; import fetch from '@system.fetch'; fetch.fetch({ url: 'http://www.baidu.com' , // 请求地址 method:'', // 请求方式 GET|OPTIONS|HEAD|POST|PUT|DELETE|TRACE data:{}, // 请求数据 string | object responseType:'json' // 返回类型 text| json success: function(response) { console.info("fetch success"); const { code , data }= JSON.stringify(response); // code 请求状态 200|500|404 , data , headers }, fail: function() { console.info("fetch fail"); } });
开启 http 支持 修改 config.json 中的 usesCleartext:true
{
"deviceConfig": {
"default": {
"network": {
"usesCleartext": true
}
...
}
}
...
}
import notification from '@system.notification';
notification.show({
contentTitle: 'title info', // 标题
contentText: 'text', // 通知内容
clickAction: {
bundleName: 'com.huawei.testapp', // 应用的bundleName
abilityName: 'notificationDemo', // 应用的abilityName
uri: '/path/to/notification', // 跳转地址
},
});
// 无需引用
// setTimeout
// clearTimeout
// setInterval
// clearInterval
import device from '@system.device'; device.getInfo({ success: function(data) { const { brand , // 品牌 manufacturer, // 生产商 model, // 型号 product, // 代号 language, // 系统语言 region, // 系统地区 windowWidth, //可使用的窗口宽度 windowHeight, //可使用的窗口高度 screenDensity, //屏幕密度 screenShape, // 可取值:rect:方形屏;circle:圆形屏 apiVersion , //系统API版本号 releaseType, // deviceType // 设备类型 tablet|phone|tv|wearable|liteWearable|smartVision } = data console.log('Device information obtained successfully. Device brand:' + data.brand); }, fail: function(data, code) { console.log('Failed to obtain device information. Error code:'+ code + '; Error information: ' + data); }, });
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。