cd /Users/lidefan/Develop/orderApp/line-order-app
npm install
npm run dev
npm run build
npm run preview
编辑 .env.development:
# API地址 - 替换为你的实际API地址
VITE_API_URL=https://your-dev-api.com
# WebSocket地址 - 替换为你的实际WS地址
VITE_WS_URL=wss://your-dev-ws.com
# LIFF ID - 在LINE Developers Console获取
VITE_LIFF_ID=1234567890-abcdefgh
# 租户ID
VITE_TENANT_ID=1
编辑 .env.production:
VITE_API_URL=https://your-prod-api.com
VITE_WS_URL=wss://your-prod-ws.com
VITE_LIFF_ID=your-prod-liff-id
VITE_TENANT_ID=1
src/
├── api/ # API接口层
│ ├── request.js # Axios封装
│ ├── auth.js # 认证API
│ ├── user.js # 用户API
│ ├── goods.js # 商品API
│ ├── order.js # 订单API
│ └── ...
│
├── assets/ # 静态资源
│ └── styles/ # 全局样式
│
├── components/ # 公共组件
│ ├── common/ # 通用组件
│ └── business/ # 业务组件
│
├── composables/ # 组合式函数
│ └── useLiff.js # LIFF hooks
│
├── config/ # 配置文件
│ └── index.js # 全局配置
│
├── locale/ # 国际化
│ ├── zh-Hans.json # 简体中文
│ ├── zh-Hant.json # 繁体中文
│ ├── ja.json # 日语
│ └── en.json # 英语
│
├── router/ # 路由
│ ├── index.js # 路由入口
│ ├── routes.js # 路由配置
│ └── guards.js # 路由守卫
│
├── store/ # 状态管理
│ ├── index.js # Pinia入口
│ └── modules/ # Store模块
│ ├── app.js # 应用状态
│ ├── user.js # 用户状态
│ ├── cart.js # 购物车
│ └── order.js # 订单状态
│
├── utils/ # 工具函数
│ ├── storage.js # 存储工具
│ ├── format.js # 格式化工具
│ ├── validate.js # 验证工具
│ ├── image.js # 图片工具
│ └── price.js # 价格工具
│
├── views/ # 页面视图
│ ├── index/ # 首页
│ ├── menu/ # 菜单
│ ├── order/ # 订单
│ ├── mine/ # 我的
│ ├── cart/ # 购物车
│ └── login/ # 登录
│
├── App.vue # 根组件
└── main.js # 入口文件
在 src/views/ 下创建新目录:
<!-- src/views/example/example.vue -->
<template>
<div class="example-page">
<van-nav-bar title="示例页面" fixed left-arrow @click-left="$router.back()" />
<div class="page-content" style="padding-top: 46px">
<!-- 页面内容 -->
</div>
</div>
</template>
<script setup>
// 导入需要的模块
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
</script>
<style scoped>
.example-page {
min-height: 100vh;
background: #f5f5f5;
}
</style>
在 src/router/routes.js 添加:
{
path: '/example',
name: 'Example',
component: () => import('@/views/example/example.vue'),
meta: {
title: 'example.title',
requiresAuth: false
}
}
在 src/api/ 下创建新文件:
// src/api/example.js
import request from './request'
export function getExampleList(params) {
return request({
url: '/api/example/list',
method: 'get',
params
})
}
Vant组件已配置自动导入,直接使用即可:
<template>
<van-button type="primary">按钮</van-button>
<van-cell title="单元格" />
<van-image src="https://example.com/image.jpg" />
</template>
<template>
<div>{{ $t('menu.title') }}</div>
</template>
<script setup>
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
console.log(t('menu.title'))
</script>
<script setup>
import { useUserStore, useCartStore } from '@/store'
const userStore = useUserStore()
const cartStore = useCartStore()
// 使用状态
console.log(userStore.isLogin)
console.log(cartStore.cartCount)
// 调用方法
userStore.setToken('xxx')
cartStore.addToCart({ id: 1, name: '商品' })
</script>
<script setup>
import { useLiff } from '@/composables/useLiff'
const { isReady, isLoggedIn, profile, login, scanCode } = useLiff()
// LIFF已在App.vue中初始化
// 登录
const handleLogin = () => {
if (!isLoggedIn.value) {
login()
}
}
// 扫码
const handleScan = async () => {
try {
const result = await scanCode()
console.log('扫码结果:', result)
} catch (error) {
console.error('扫码失败:', error)
}
}
</script>
# 安装依赖
npm install
# 开发模式 (热更新)
npm run dev
# 构建生产版本
npm run build
# 预览生产构建
npm run preview
# 查看依赖包大小
npm run build -- --report
# 清除缓存重新安装
rm -rf node_modules package-lock.json
npm install
修改 vite.config.js:
server: {
port: 3001, // 修改端口
}
检查:
检查:
.env.development中的API地址如遇问题:
🎉 祝开发顺利!