图书项目要点

一、搭建项目

使用tarojs/cli进行搭建

taro init [项目名]

二、具体页面

页面声明:

在【app.config.ts】中对主页面进行声明:组件页面可以不用声明

TypeScript 复制代码
pages: [
    "pages/index/index",
    'pages/user/index',
    'pages/book/index',
  ],

tabbar制作:

在【app.config.ts】中写入代码:

TypeScript 复制代码
tabBar: {
    color: '#333',
    selectedColor: '#1cbbb4',
    backgroundColor: '#fff',
    borderStyle: 'black',
    list: [
      {
        pagePath: 'pages/index/index',
        text: '首页',
        iconPath: './assets/tabbar/home.png',
        selectedIconPath: './assets/tabbar/home_active.png'
      },
      {
        pagePath: 'pages/book/index',
        text: '书架',
        iconPath: './assets/tabbar/book.png',
        selectedIconPath: './assets/tabbar/book_active.png'
      },
      {
        pagePath: 'pages/user/index',
        text: '我的',
        iconPath: './assets/tabbar/mine2.png',
        selectedIconPath: './assets/tabbar/mine2_active.png'
      },
    ]
  },
};

【我的】:

页面效果:

【user/index.tsx】页面代码:

TypeScript 复制代码
import { View, Text, Button, Image } from "@tarojs/components";

import './index.less'
import AutorBar from "@/components/AutorBar";
import Line from "@/components/Line";
import TextBar from "@/components/TextBar";


const list = [
  { title: '我的收藏', icon: require('../../assets/collect.png') },
  { title: '借阅记录', icon: require('../../assets/read.png') },
  { title: '留言板', icon: require('../../assets/message.png') },
]

const User = () => {


  return (
    <View className="wrapper">
      <AutorBar></AutorBar>
      <Line></Line>

      <View className="title"> 最近阅读 </View>
      
      <Line></Line>

      <View>
        {
          list.map((item, index) => <TextBar {...item}></TextBar>)
        }
      </View>
    </View>
  );
};

export default User;

【user/index.less】样式文件:

css 复制代码
page {
    background-color: white;
    padding         : 14px;
    box-sizing      : border-box;
    color           : #333;
  }
  
  .wrapper {
    display       : flex;
    flex-direction: column;
  }

  .title{
    padding: 20px 0;
    font-weight: bold;
  }
  
   

【user/index.config.ts】文件

TypeScript 复制代码
export default {
    navigationBarTitleText: '图书',
    enableShareAppMessage: true,
  };
  

【书架页面】:

效果如下:

【book/index.tsx】:

TypeScript 复制代码
import { View, Text, Button, Image } from "@tarojs/components";

import './index.less'
import HistoryBar from "@/components/HistoryBar";

const bookIndex = require('../../data/detail_400000.json')
const bookList = require('../../data/books_1500000.json')

const Book = () => {
  console.log(bookIndex, 'bookIndex')
  return (
    <View className="wrapper">

      <View className="title"> 热门推荐 </View>
      <HistoryBar bookList={bookList}></HistoryBar>

      
    </View>
  );
};

export default Book;

【book/index.less】:

css 复制代码
page {
  background-color: white;
  padding         : 14px;
  box-sizing      : border-box;
  color           : #333;
  background-color: #f6f6f6;
}

.wrapper {
  display       : flex;
  flex-direction: column;
}

.title{
    padding: 20px 0;
    font-weight: bold;
  }
  

【book/index.config.ts】:

css 复制代码
export default {
    navigationBarTitleText: '图书',
    enableShareAppMessage: true,
  };
  

【主页】效果如下:

【index/index.tsx】

TypeScript 复制代码
import React, { useCallback } from "react";
import { View, Text, Button, Image } from "@tarojs/components";
import { useEnv, useNavigationBar, useModal, useToast } from "taro-hooks";

import './index.less'
import ComBar from "src/components/ComBar";
import Search from "@/components/Search";

const Index = () => {

  return (
    <View className="wrapper">
        <Search></Search>
        <ComBar></ComBar>
    </View>
  );
};

export default Index;

【index/index.less】:

TypeScript 复制代码
page {
  background-color: white;
  padding         : 14px;
  box-sizing      : border-box;
  color           : #333;
}

 .cardList{
  display: flex;
  flex-wrap: wrap;
 }

【Combar】组件

TypeScript 复制代码
import { ScrollView, View, Image, Text } from "@tarojs/components"
 

import './index.less'

const list =[
    { title: '精品推荐', icon: require('./images/icon0.png') },
    { title: '历史', icon: require('./images/icon1.png')},
    { title: '文学', icon: require('./images/icon2.png') },
    { title: '艺术', icon: require('./images/icon3.png') },
    { title: '人物传记', icon: require('./images/icon4.png') },
    { title: '自然科学', icon: require('./images/icon5.png') },
    { title: '国外读物', icon: require('./images/icon6.png') }
  ]

const ComBar = () => {
    return (<ScrollView className="combar" scrollX >
        {
            list.map(item => <View key={item.title} className="combarItem">
                <View className="combarItemView"><Image className="combarItemImage" src={item.icon}></Image></View>
                <View className="combarItemText">{item.title}</View>
            </View>)
        }
    </ScrollView>)
}

export default ComBar

整体效果:

相关推荐
sunshine641几秒前
【CSS】实现tag选中对钩样式
前端·css·css3
PyAIGCMaster5 分钟前
ubuntu装P104驱动
linux·运维·ubuntu
奈何不吃鱼6 分钟前
【Linux】ubuntu依赖安装的各种问题汇总
linux·运维·服务器
icy、泡芙8 分钟前
T527-----音频调试
linux·驱动开发·音视频
aherhuo11 分钟前
kubevirt网络
linux·云原生·容器·kubernetes
zzzhpzhpzzz19 分钟前
Ubuntu如何查看硬件型号
linux·运维·ubuntu
蜜獾云22 分钟前
linux firewalld 命令详解
linux·运维·服务器·网络·windows·网络安全·firewalld
真滴book理喻23 分钟前
Vue(四)
前端·javascript·vue.js
陌北v124 分钟前
Docker Compose 配置指南
运维·docker·容器·docker-compose
蜜獾云26 分钟前
npm淘宝镜像
前端·npm·node.js