一、配置tabBar页面
app.json 是全局配置文件,用于配置小程序的信息(它里面配置的是全局信息)
{
pages目录 用于存放所有的页面
"pages": [
"pages/index/index",
"pages/list/list",
"pages/order/order",
"pages/shopcart/shopcart",
"pages/mine/mine",
"pages/detail/detail"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#369",
"navigationBarTitleText": "KW43-APP",
"navigationBarTextStyle": "white"
},
"tabBar": {
颜色
"color": "#000000",
选中颜色
"selectedColor": "#336699",
背景颜色
"backgroundColor": "#ffffff",
"borderStyle": "black",
最少设置两个,最多设置五个
"list": [
{
"text": "首页",
"pagePath": "pages/index/index",
图片尺寸为81*81
"iconPath": "assets/icon/home.png",
"selectedIconPath": "assets/icon/home2.png"
},
{
"text": "列表",
"pagePath": "pages/list/list",
"iconPath": "assets/icon/list.png",
"selectedIconPath": "assets/icon/list2.png"
},
{
"text": "订单",
"pagePath": "pages/order/order",
"iconPath": "assets/icon/order.png",
"selectedIconPath": "assets/icon/order2.png"
},
{
"text": "购物车",
"pagePath": "pages/shopcart/shopcart",
"iconPath": "assets/icon/shopcart.png",
"selectedIconPath": "assets/icon/shopcart2.png"
},
{
"text": "我的",
"pagePath": "pages/mine/mine",
"iconPath": "assets/icon/mine.png",
"selectedIconPath": "assets/icon/mine2.png"
}
],
tabBar显示位置,默认是到底部,如果放置顶部会不显示图标
"position": "bottom"
},
这个属性代表后期可以引用自定义组件
"usingComponents": {},
"style": "v2",
sitemap.json 是SEO配置文件,文件用于配置小程序及其页面是否允许被微信索引文件内容为一个JSON
"sitemapLocation": "sitemap.json"
}
二、小程序页面跳转
(1)navigator相当于是a连接
普通页面的跳转,url写地址即可,跳转后可返回
<navigator url="../detail/detail">到详情页</navigator>
跳转tabBar页面,需要加属性open-type="switchTab",跳转后没有返回键
<navigator url="../list/list" open-type="switchTab">到列表页</navigator>
(2)使用点击事件跳转页面
跳转普通页面,跳转后可返回
<view class="btns" bindtap="gotoDetail">到详情页</view>
跳转到详情页
gotoDetail(){
使用全局api跳转,navigateTo()方法,用于跳转普通页面
wx.navigateTo({
url: '../detail/detail',
})
},
跳转tabBar页面,跳转后没有返回键
<view class="btns" bindtap="gotoList">到列表页</view>
跳转到列表页
gotoList(){
switchTab()方法,用于跳转tabBar页面
wx.switchTab({
url: '../list/list',
})
}
(3)跳转其他小程序,
需要添加target,默认值是self跳转自己小程序页面,miniProgram是跳转其他小程序的页面
<navigator target="miniProgram"></navigator>
三、删除确认框和提示框
(1)showModal()方法,打开确认框
(2) showToast()方法,打开消息框
删除指定热门歌曲
delSong1(e){
showModal()方法,打开确认框
wx.showModal({
content:'是否确定删除',
调用成功的接口
success:({confirm})=>{
confirm返回true,表示点击的是确定按钮,否则是取消按钮
if(confirm){
解构出对应的索引
let {currentTarget:{dataset:{index}}} = e
this返回的是当前页面对象
this.data.songs1.splice(index,1)
删除完后,重新渲染页面
setData()方法,设置重新更新页面中哪些数据
this.setData({
songs1:this.data.songs1
})
showToast()方法,打开消息框
wx.showToast({
title: '删除成功',
icon:"success",
duration:1500,
mask:true
})
}
接口调用失败的回调函数
fail: () => { },
接口调用结束的回调函数(成功,失败都会执行)
complete: () => { }
}
})}