1问题描述1 p* Y+ \8 R7 V9 S5 W; S5 o0 V
使用微信小程序开发者工具制作顶部导航栏。
6 i" a" n/ N$ ?. E
' ]' L4 t& c/ S8 \/ b8 F4 q& t
2算法描述
& H, t: v$ e$ d* o4 f; ~! W9 z9 d
& E+ c8 y9 [ h+ x0 G8 i4 }* W 首先就是对微信小程序开发者工具的配置,官网搜索后进入,选择稳定版,Windows64位下载。
, c% u. n- w k2 [3 N
- ^$ t- ] g7 h+ C
, Y# B! O2 g! u9 G8 H4 V
然后点开开发者工具,选择小程序,点击图片位置的加号,进入创建页面,可以更改项目名称和文件所在目录。0 o! b+ t' n8 W, v& t" B
注意,在AppID中我们先选择使用测试号,然后点击确定- A+ z- r& B. a9 t7 p* Z
进入程序后,选择index.js文件,编辑data内容,再在index.wxml文件中加上文字页面,index.wxss文件中可以更改获取的图片信息。
V4 Y* F+ V4 ?4 |5 M& O, T 要注意的是,最好不要直接在微信开发者工具中写代码,这里可以使用vscode,使用Java工具。
# ^7 V6 t& V" I3 代码
$ u2 R& h* i7 x: b' y1 f; t& ?: p0 F) t0 w
index.jx
var app = getApp()
Page({
data: {
navbar: ['科普点', '动物场馆', '游览点','卫生间'],
currentTab: 0
},
navbarTap: function(e){
this.setData({
currentTab: e.currentTarget.dataset.idx
})
}
})
index.wxml
<!--导航条-->
<view class="navbar">
<text wx:for="{{navbar}}" data-idx="{{index}}" class="item {{currentTab==index ? 'active' : ''}}" wx:key="unique" bindtap="navbarTap">{{item}}</text>
</view>
<!--科普点-->
<view hidden="{{currentTab!==0}}">
tab_01
</view>
<!--动物场馆-->
<view hidden="{{currentTab!==1}}">
tab_02
</view>
<!--游览点-->
<view hidden="{{currentTab!==2}}">
tab_03
</view>
index.wxss
page{
display: flex;
flex-direction: column;
height: 100%;
}
.navbar{
flex: none;
display: flex;
background: #fff;
}
.navbar .item{
position: relative;
flex: auto;
text-align: center;
line-height: 80rpx;
}
.navbar .item.active{
color: #FFCC00;
}
.navbar .item.active:after{
content: "";
display: block;
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 4rpx;
background: #FFCC00;
}
|