【小程序】多端框架Taro实现外卖首页

本文介绍了使用Taro开发微信小程序项目的流程,包括全局安装Taro命令行工具、创建模板项目、安装第三方依赖、编写详细代码、编译打包生成dist目录并导入微信开发者工具。同时,还分享了Taro CLI多版本共存和无法全局卸载的解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

全局安装Taro命令行工具

npm install -g @tarojs/cli 【Taro v3.0.18】

创建模板项目

taro init myApp

安装其他第三方依赖

npm install --save taro-ui@next 安装失败,改用cnpm install --save taro-ui@next 【taro-ui@3.0.0-alpha.9】。
npm install --save events 安装失败,改用cnpm install --save events【events@3.2.0】。

代码目录

在这里插入图片描述

详细代码
修改index.jsx
import React, {
    Component } from 'react';
import {
    View} from '@tarojs/components';
import './index.scss';
import Head from "../../components/head/head.jsx";
import Food from "../../components/food/food.jsx";
import Bottom from "../../components/bottom/bottom.jsx";

class Index extends Component {
   

  render () {
   
    return (
      <View className='index'>
        <Head/>
        <Food/>
        <Bottom/>
      </View>
    )
  }
}

export default Index;
新增目录 assets/images

请移步此处下载图片。

新增commons/utils/utils.js
import Taro from "@tarojs/taro";
import EventEmitter  from "events";

function getTotal(){
   
    let buffer = Taro.getStorageSync("buffer");
    let total = 0,sum = 0;
    Object.keys(buffer).map(item => {
   
        let {
   price,quantity} = buffer[item];
        sum += quantity;
        total += price*quantity;
    })
    return {
   sum,total};
}

const Event = new EventEmitter();

export {
   
    getTotal,
    Event
}
新增目录components/bottom
bottom.jsx
import React,{
   Component} from "react";
import {
   View,Image,Text} from "@tarojs/components";
import "./bottom.scss";
import {
   Event,getTotal} from "../../common/utils/utils.js";

class Bottom extends Component{
   
    constructor(){
   
        super(...arguments);
        this.state = {
   
            total:0,
            sum:0,
            delivery:15,
            starting:20
        }
    }
    componentDidMount(){
   
        let {
   total,sum} = getTotal();
        this.setState({
   
            total:total,
            sum:sum
        })
        Event.on("change",() => {
   
            let {
   total,sum} = getTotal();
            this.setState({
   
                total:total,
                sum:sum
            })
        })
    }
    render(){
   
        let {
   total,sum,delivery,starting} = this.state;
        return (
            <View className="bottom">
                <View className="bottom-content">
                    {
   
                        (sum>0) 
                        ? <><Text className="sum">{
   sum}</Text><Image className="expressman" src={require("../../assets/images/expressman_light.png")}></Image></>
                        : <Image className="expressman" src={
   require("../../assets/images/expressman_dark.png")}></Image>
                    }
                    <View className="cost">
                        <Text className="total"><Text className="value">{
   total}</Text></Text>
                        <Text className="delivery">预估送配送费¥{
   total<starting?delivery:0}</Text>
                    </View>
                    {
   (total<starting)
                        ?<View className="starting"><Text>{
   starting}起送</Text></View>
                        :<View className="gotoPay">去结算</View>
                    }       
                </View>
            </View>
        )
    }
}

export default Bottom;
bottom.scss
.bottom{
   
    padding: 0 24px;
    box-sizing: border-box;
    width: 100%;
    height: 100px;
    position: fixed;
    bottom: 0;
    .bottom-content{
   
        height: inherit;
        background-color: #020001;
        border-radius: 60px;
        display: flex;
        color: #6a6a6a;
        justify-content: space-between;
        align-items: center;
        font-size: 26px;
        .sum{
   
            width: 36px;
            height: 36px;
            line-height: 36px;
            display: inline-block;
            background-color: #fa4e3f;
            color: #fff;
            text-align: center;
            border-radius: 50%;
            position: absolute;
            bottom: 10px;
            left: 150px;
        }
        .expressman{
   
            width: 128px;
            height: 128px;
            margin-top: -30px;
            margin-left:50px;
        }
        .cost{
   
            margin-left: -30px;
            display: flex;
            align-items: center;
        }
        .total{
   
            color: #fff;
            font-size: 28px;
            padding-right: 10px;
        }
        .value{
   
            font-size: 42px;
        }
        .delivery{
   
            padding-left: 10px;
            border-left: 1px solid #666;
        }
        .starting{
   
            margin-right: 50px;
        }
        .gotoPay{
   
            width: 150px;
            height: 100px;
            line-height: 100px;
            text-align: center;
            border-top-right-radius: 60px;
            border-bottom-right-radius: 60px;
            background-color: #ffc236;
            box-shadow: 1px 0 0 #ffc236;
        }
    }

}
新增目录components/food
category.jsx
地方订餐外卖网站系统 2015 2016 最赚钱的项目,帮您打造本地商业门户,机遇不可错过。网上订餐系统_网络订餐系统_外卖网站建设.订餐网,外卖网源码,带积分商城,商家系统,外卖网站建设! 系统特点: 周密策划、项目为先 "项目指导技术,技术服从项目",这是我们一贯秉承的原则,也是我们与其他系统开发商、网站建设公司的本质区别所在!我们的每个系统作品都要经过周密的市场分析调查、可行性研究、项目策划,对我们来说项目的可行性高于一切! 功能专业、布局严谨 以项目方案为蓝本,以现有成功地方网站为局部参考,并充分结合地方性网站的特点与商业模式进行功能规划。系统以八大主要功能模块与诸多 实用辅助模块组成,专业、强大、实用、易用。在布局上科学严谨,给用户以完美影像! 顶尖设计、赏心悦目 深知“面子”在网站中举足轻重位置,本系统由多名资深网页设计师联合设计,所有页面均经过布局策划-页面与UI设计-美术设计三大环节,结构布局清晰、界面大气美观、干净整洁,并注重每个细节的用户体验。让您的网站在用户面前眼前一亮! 饿了么源码网络外卖订餐系统致力于帮助专业从事餐饮外卖企业或有外卖业务的餐饮企业快速部署外卖订餐系统,拓展网络外卖订餐业务。简洁大方的界面、精准的楼宇定位系统、强大的菜单管理系统,人性化的订单处理系统等等,不仅能够帮助您提升企业形象、还为您提供了一套完整的网络外卖解决方案,配合适当的宣传方式可以获得实实在在的销量和用户黏度的提升。 都来订网络外卖订餐系统区别于同类软件产品的独特性表现在: 1、 简洁大方的界面 简洁的界面,简便的操作,全面提升企业形象,带给您全新的体验。 2、 精准的楼宇定位系统 配送范围、配送价格、配送时间随需变化。 3、 强大的菜单管理系统 单品、套餐均适用,图片展示更直观。 4、 人性化的订单处理系统 订单提示、处理、打印、对账,一站式完成。 5、 快捷流畅的订餐流程 定位→选餐→下单→结算,保证订单准确无误。 6、 及时发布公告信息 将营业状态和促销信息第一时间发布到网站。 都来订网络外卖订餐系统V1.8.6更新内容简介: 1、提高首页点餐速度;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值