이 글의 내용은 WeChat 애플릿의 하단 타르바를 사용자 정의하는 코드 구현에 관한 것입니다. 필요한 친구들이 참고할 수 있기를 바랍니다.
먼저 디렉토리를 살펴보세요
탭바 템플릿은 템플릿 폴더에 저장되어 있습니다.
template/template.wxml
<template name="tabBar"> <view class="tabBar"> <block wx:for="{{tabBar}}" wx:for-item="item" wx:key="tabBar"> <view class="tabBar-item"> <navigator open-type="redirect" url="{{item.pagePath}}"> <view><image class="icon" src='{{item.iconPath}}'></image></view> <view class="{{item.current== 1 ? 'tabBartext' :''}}">{{item.text}}</view> </navigator> </view> </block> </view> </template>
template.css
.icon{ width:54rpx; height: 54rpx; } .tabBar{ width:100%; position: fixed; bottom:0; padding:10rpx; margin-left:-4rpx; background:#F7F7FA; font-size:20rpx; color:#8A8A8A; box-shadow: 6rpx 6rpx 6rpx 6rpx #aaa; } .tabBar-item{ float:left; width:25%; text-align: center; overflow: hidden; } /*当前字体颜色*/ .tabBartext{ color:red; }
template.js
//初始化数据 function tabbarinit() { return [ { "current":0, "pagePath": "/pages/index/index", "iconPath": "/imgs/home.png", "selectedIconPath": "/imgs/home_on.png", "text": "主页" }, { "current": 0, "pagePath": "/pages/news/news", "iconPath": "/imgs/message.png", "selectedIconPath": "/imgs/message_on.png", "text": "资讯" }, { "current": 0, "pagePath": "/pages/category/category", "iconPath": "/imgs/category.png", "selectedIconPath": "/imgs/category_on.png", "text": "分类" }, { "current": 0, "pagePath": "/pages/buy/buy", "iconPath": "/imgs/buy.png", "selectedIconPath": "/imgs/buy_on.png", "text": "购物" } ] } //tabbar 主入口 function tabbarmain(bindName = "tabdata", id, target) { var that = target; var bindData = {}; var otabbar = tabbarinit(); otabbar[id]['iconPath'] = otabbar[id]['selectedIconPath']//换当前的icon otabbar[id]['current'] = 1; bindData[bindName] = otabbar that.setData({ bindData }); } module.exports = { tabbar: tabbarmain }
이것으로 컴포넌트 수정이 완료되고, 사용법을 설명합니다.
먼저 스타일을 index 폴더의 app.wxss
@import "/template/template.wxss";
에 로드합니다.
index.wxml
<import src="../../template/template.wxml"/> <template is="tabBar" data="{{tabBar:bindData.tabBar}}"/>
index.js
const app = getApp() var template = require('../../template/template.js'); Page({ data: { }, onLoad: function () { template.tabbar("tabBar", 0, this)//0表示第一个tabbar }, })
news.wxml은 index.wxml과 동일합니다.
news.js는 다음과 같습니다
const app = getApp() var template = require('../../template/template.js'); Page({ data: { }, onLoad: function () { template.tabbar("tabBar", 1, this)//1表示第二个tabbar }, })
효과는 그림과 같습니다
관련 추천:
WeChat 애플릿 예: 탐색 모음이 함께 움직일 때 상단 탭 전환 및 슬라이딩 전환 효과 실현(코드)
WeChat 애플릿 예: 도시 위치 및 재승인된 지리적 위치의 현재 코드 구현을 가져옵니다
위 내용은 하단 타르바를 사용자 정의하는 WeChat 애플릿의 코드 구현의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.