1问题描述
# B4 F- ?) J4 M3 z) x- a! k7 Q$ v 使用微信小程序开发者工具制作顶部导航栏。- S/ C( z* l6 D* _
/ D) M) Y- o7 c6 b6 M8 N
2算法描述( N# ~1 p4 d- h; N a
7 k9 u. }0 x, W6 c0 h" Q 首先就是对微信小程序开发者工具的配置,官网搜索后进入,选择稳定版,Windows64位下载。
1 f7 _, ^; z8 @; V* R2 s
3 P# U& \" w/ ` ?9 }6 r4 t! f
n8 ^/ B. X# T; x( _ 然后点开开发者工具,选择小程序,点击图片位置的加号,进入创建页面,可以更改项目名称和文件所在目录。4 E, y* a2 F0 n$ o: \7 B
注意,在AppID中我们先选择使用测试号,然后点击确定
! b7 q e6 R! Z* W! o6 F8 g 进入程序后,选择index.js文件,编辑data内容,再在index.wxml文件中加上文字页面,index.wxss文件中可以更改获取的图片信息。
4 p0 ]; }2 M5 Y7 }, U 要注意的是,最好不要直接在微信开发者工具中写代码,这里可以使用vscode,使用Java工具。
* T. ^% m2 S; B; n3 代码- y) y, F% n" p5 L8 P9 d
. F1 Y7 `" f v& ` E5 k
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;
}
|