外观
外观
怡然
1517字约5分钟
2024-07-18
manifest.json
pages.json
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": { // 属性与下方全局属性的配置一致,在页面样式配置会覆盖全局的配置
"navigationBarTitleText": "遗愿清单"
}
},
{
"path" : "pages/list/list",
"style" :
{
"navigationBarTitleText" : "我的清单"
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black", // 导航栏标题颜色,仅支持black和white
"navigationBarTitleText": "uni-app", // 导航栏标题文字内容,权重低于上面页面配置的权重
"navigationBarBackgroundColor": "#F8F8F8", // 导航栏背景颜色
"enablePullDownRefresh": true, // 是否开启下拉刷新
"backgroundColor": "#F8F8F8", // 下拉刷新的背景色
"backgroundTextStyle": "dark", // 下拉刷新时三个点的颜色
"onReachBottomDistance": 500, // 触底更新的距离,配合页面生命周期的onReachBottom使用
"navigationStyle": "custom" // 导航栏样式,配置为custom以后上述对导航栏的设置会失效
},
"tabBar": { // 下方导航栏
"color": "#494949", // 文字颜色
"selectedColor": "#aa699f", // 选中文字颜色
"backgroundColor": "#fff", // 底部导航背景颜色
"borderStyle": "white", // 边框样式
"position": "top", // 导航栏位置,默认在底部,top只有微信小程序支持
"list": [ // 导航列表,数量最少两个最多五个
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "", // 默认情况下icon路径,需设置大小为81px,不支持网络图片
"selectedIconPath": "" // 选中情况下icon路径
},
{
"pagePath": "pages/list/list",
"text":"清单"
}
]
},
"uniIdRouter": {}
}
rpx
padding-bottom: env(safe-area-inset-bottom); // 安全区域距离底部的距离
showToast
与hideToast
showToast
uni.showToast({
title:'成功', // 显示文字
icon:'success', // 图标类型,设置为none时title的文字可以在小程序中换行显示
image:'', // 不设置icon可以自己设置图片
mask:true, // 是否显示透明蒙层,防止触摸穿透
duration:2000, // 显示时间,单位ms
success:function(res){ // 成功回调
console.log(res)
},
fail:function(res){ // 失败回调
console.log(res)
},
complete:function(res){ // 结束回调
}
})
hideToast
uni.hideToast() // 关闭提示框
showLoading
与hideLoading
uni.showLoading({
title:'加载中...', // 显示文字
mask:true, // 是否显示透明蒙层,防止触摸穿透
success:function(res){ // 成功回调
console.log(res)
},
fail:function(res){ // 失败回调
console.log(res)
},
complete:function(res){
// 结束回调
}
})
showModal
模态框uni.showModal({
title:'是否删除', // 模态框标题
content:'xxxxxxxx', // 详细描述
showCancel:true, // 是否显示取消按钮
cancelText:'取消', // 取消按钮文字
cancelColor:'#000000', // 取消按钮文字颜色
confirmText:'确定', // 确定按钮文字
confirmColor:'#3CC51F', // 确定按钮文字颜色
editable:true, // 是否显示输入框
placeholderText:'请输入', // 输入框提示文字
success:function(res){ // 成功回调
console.log(res)
},
fail:function(res){ // 失败回调
},
complete:function(res){ // 结束回调
}
})
showActionSheet
uni.showActionSheet({
title:'提示文字', // 非必填
itemList:["本科","专科","中专","高中","初中","小学","幼儿园"],
itemColor:'#333333', // 选项颜色
success:function(res){ // 成功回调,其余的回调函数同上述
},
})
uni.setNavigationBarTitle({
title:''
})
uni.setNavigationBarColor({
// 设置页面导航条颜色。如果需要进入页面就设置颜色,请延迟执行,防止被框架内设置颜色逻辑覆盖
})
uni.showNavigationBarLoading({
// 在当前页面显示导航条加载动画。
})
uni.hideNavigationBarLoading() // 在当前页面隐藏导航条加载动画。
uni.hideHomeButton() // 隐藏返回首页按钮。
tabBar
(参考官方文档)uni.setStorage
和uni.getStorage
uni.setStorage({
key: 'storage_key',
data: 'hello',
success: function () {
console.log('success');
}
});
uni.getStorage({
key: 'storage_key',
success: function (res) {
console.log(res.data);
}
});
uni.setStorageSync
和uni.getStorageSync
uni.setStorageSync('storage_key', 'hello');
const value = uni.getStorageSync('storage_key');
uni.removeStorage
和uni.removeStorageSync
uni.removeStorage({
key: 'storage_key',
success: function (res) {
console.log('success');
}
});
uni.removeStorageSync('storage_key');
uni.clearStorage
和uni.clearStorageSync
uni.clearStorage();
uni.clearStorageSync();
uni.getStorageInfo
和uni.getStorageInfoSync
uni.getStorageInfo({
success: function (res) {
console.log(res.keys);
console.log(res.currentSize);
console.log(res.limitSize);
}
});
const res = uni.getStorageInfoSync();
console.log(res.keys);
console.log(res.currentSize);
console.log(res.limitSize);
const requestTask = uni.request({
url: 'https://www.example.com/request', //仅为示例,并非真实接口地址。
data: {
name: 'name',
age: 18
},
method: 'POST', // 接口方式
header:{
token:''
contentType:'application/json'
},
dataType: 'json', // 接口数据类型
timeout: 10000, // 超时时间
success: function(res) {
console.log(res.data);
},
fail: function(err) {
console.log(err);
},
complete: function(res) {
}
});
// 中断请求任务
requestTask.abort();
.then()
或者async await
const requestTask = uni.request({
url: 'https://www.example.com/request', //仅为示例,并非真实接口地址。
data: {
name: 'name',
age: 18
},
}).then(res=>{
console.log(res.data);
})
async function getData(){
const res = await uni.request({
url: 'URL_ADDRESS', //仅为示例,并非真实接口地址。
data: {
name: 'name',
age: 18
},
});
console.log(res.data);
}