1问题描述
1 q! N6 X& [2 K' X4 w( O1 ~ 使用微信小程序开发者工具制作顶部导航栏。; T v2 U' o& \ a1 P" h0 U) R. Y% u
* X5 B: n( f& T \( j i8 \! _0 R2算法描述
, S7 A) r1 S' ~4 P& }% ?6 G
% ?' c6 Y# S. `9 g* j 首先就是对微信小程序开发者工具的配置,官网搜索后进入,选择稳定版,Windows64位下载。
3 L; a& z: h) V" R5 D: c3 q. X" j& Y4 n
, w3 n. q6 L, ]- p- ~
. A. {( g* V0 C) L6 s% J! K' f 然后点开开发者工具,选择小程序,点击图片位置的加号,进入创建页面,可以更改项目名称和文件所在目录。
% d0 ]! Z0 v1 ^; | b& h. B, c4 T 注意,在AppID中我们先选择使用测试号,然后点击确定2 V2 b6 n8 p! j8 ~
进入程序后,选择index.js文件,编辑data内容,再在index.wxml文件中加上文字页面,index.wxss文件中可以更改获取的图片信息。1 V9 W# g2 o9 c' X% F& I0 `/ `1 }4 T
要注意的是,最好不要直接在微信开发者工具中写代码,这里可以使用vscode,使用Java工具。% S5 x* [7 ]+ C5 X4 c) ]5 E& v
3 代码
& i% u& b9 o- d& L7 S- v
' G3 [! _9 s1 z. n6 _6 h3 g% l1 Uindex.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;
}
|