{"id":13506917,"url":"https://github.com/EasyTuan/nuxt-elm","last_synced_at":"2025-03-30T05:31:28.201Z","repository":{"id":109151315,"uuid":"145271547","full_name":"EasyTuan/nuxt-elm","owner":"EasyTuan","description":"基于nuxt2+vue构建的全栈开源项目","archived":false,"fork":false,"pushed_at":"2019-07-26T03:36:51.000Z","size":7784,"stargazers_count":347,"open_issues_count":5,"forks_count":114,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-23T16:07:11.870Z","etag":null,"topics":["mint-ui","nuxt","vue-router","vue2","vuex"],"latest_commit_sha":null,"homepage":"https://elm.caibowen.net/","language":"Vue","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EasyTuan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-08-19T04:00:02.000Z","updated_at":"2025-02-19T08:55:52.000Z","dependencies_parsed_at":"2023-03-13T14:15:45.866Z","dependency_job_id":null,"html_url":"https://github.com/EasyTuan/nuxt-elm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyTuan%2Fnuxt-elm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyTuan%2Fnuxt-elm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyTuan%2Fnuxt-elm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyTuan%2Fnuxt-elm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EasyTuan","download_url":"https://codeload.github.com/EasyTuan/nuxt-elm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246281098,"owners_count":20752203,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mint-ui","nuxt","vue-router","vue2","vuex"],"created_at":"2024-08-01T01:00:59.990Z","updated_at":"2025-03-30T05:31:28.181Z","avatar_url":"https://github.com/EasyTuan.png","language":"Vue","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"简体中文 | [English](./README_zh-EN.md)\n\n# 前言\n\n以nuxt2作为vue的服务端渲染，适合刚接触或者准备上vue ssr的同学参考和学习，\n此项目涉及注册、登录、商品展示、地址管理等等，从前端到后端到最后到服务端部署，让你体验到全栈开发到乐趣。\n\n注：项目仿照饿了么H5版本，参考2018最新UI，正常下单请选择饿了么官方客户端。\n\n如遇网络不佳，请移步[国内镜像加速节点](https://gitee.com/easytuan/nuxt-elm)\n\n# 效果演示\n\n[查看demo请戳这里](https://elm.caibowen.net/)（请用chrome手机模式预览）\n\n### 移动端扫描下方二维码\n\n\u003cimg src=\"./screenshots/qr-code.png\" width=\"250\" height=\"250\"/\u003e\n\n# API接口文档\n\n[接口文档地址](https://easytuan.gitee.io/node-elm-api/doc)（基于apidoc）\n\n# 技术栈\n\nnuxt2 + vue + vuex + vue-router + mint-ui\n\n## 项目运行\n\n```\n\ngit clone git@github.com:EasyTuan/nuxt-elm.git\n\n# 国内镜像加速节点:git@gitee.com:easytuan/node-elm-api.git\n\ncd nuxt-elm\n\nnpm install\n\nnpm run dev\n\n# 模版快速生成\nnpm run tep `文件名`\n\n# pm2部署\nnpm run start\n\n```\n\n## 补充\n\n此项目有配套的后台系统，如果想体验前后台同时开发，可以下载对应的后台系统：[后台项目传送地址](https://github.com/EasyTuan/node-elm-api)。\n\n如果只做前端开发，请忽略这句话。\n\n## 休闲一刻\n\n\u003cimg src=\"screenshots/gh_a896d27a50a3_430.jpg\" width=\"250\"/\u003e \u003cimg src=\"screenshots/gh_44a51ea2dd08_430.jpg\" width=\"250\"/\u003e\n\n\n# 目标功能\n- [x] 商家列表 -- 完成\n- [x] 购物车功能 -- 完成\n- [x] 餐馆食品列表页 -- 完成\n- [x] 店铺评价页面 -- 完成\n- [x] 商家详情页 -- 完成\n- [x] 登录、注册 -- 完成\n- [x] 修改密码 -- 完成\n- [x] 个人中心 -- 完成\n- [x] 红包 -- 完成\n- [x] 收货地址 -- 完成\n\n# 业务介绍\n\n目录结构\n\n    ├── assets                    // 静态资源\n    │   ├── images                    // 图片资源\n    │   ├── services                  // api请求\n    │   ├── styles                    // 样式文件\n    │   └── utils                     // 常用工具类\n    ├── components                // 组件\n    ├── config\n    │   └── index.js                  // 配置文件\n    ├── layouts                  // 布局\n    ├── middleware               // 中间件\n    ├── pages                    // 页面\n    ├── plugins                  // 插件\n    ├── static                   // 静态资源\n    └── store                    //vuex状态树\n\n\n## 部分截图展示\n\n### 首页展示\n\n\u003cimg src=\"screenshots/1.png\" width=\"375px\" height=\"667px\" /\u003e \u003cimg src=\"screenshots/1.gif\" width=\"375px\" height=\"667px\" /\u003e\n\n### 个人资料\n\n\u003cimg src=\"screenshots/2.png\" width=\"375px\" height=\"667px\" /\u003e \u003cimg src=\"screenshots/2.gif\" width=\"375px\" height=\"667px\" /\u003e\n\n### 我的\n\n\u003cimg src=\"screenshots/3.png\" width=\"375px\" height=\"667px\" /\u003e \u003cimg src=\"screenshots/3.gif\" width=\"375px\" height=\"667px\" /\u003e\n\n### 订餐\n\n\u003cimg src=\"screenshots/4.png\" width=\"375px\" height=\"667px\" /\u003e \u003cimg src=\"screenshots/4.gif\" width=\"375px\" height=\"667px\" /\u003e\n\n### 商家评价\n\n\u003cimg src=\"screenshots/5.png\" width=\"375px\" height=\"667px\" /\u003e \u003cimg src=\"screenshots/5.gif\" width=\"375px\" height=\"667px\" /\u003e\n\n# 说明\n\n\u003e  如果对您有帮助，您可以点右上角 \"Star\" 支持一下 谢谢！ ^_^\n\n\u003e  或者您可以 \"follow\" 一下，我会不断开源更多的有趣的项目\n\n\u003e  如有问题请直接在 Issues 中提，或者您发现问题并有非常好的解决方案，欢迎 PR 👍\n\n# 开发日常记录\n\n### nuxt模版搭建\n\n这里关于项目初始化，我是直接使用的 `Nuxt` 官网提供的 create-nuxt-app\n\n```shell\n\n# 确保安装了npx（npx在NPM版本5.2.0默认安装了）：\nnpx create-nuxt-app \u003c项目名\u003e\n\n它会让你进行一些选择:\n  1.在集成的服务器端框架之间进行选择:\n    None (Nuxt默认服务器)\n    Express\n    Koa\n    Hapi\n    Feathers\n    Micro\n    Adonis (WIP)\n  2.选择您喜欢的UI框架:\n    None (无)\n    Bootstrap\n    Vuetify\n    Bulma\n    Tailwind\n    Element UI\n    Buefy\n  3.选择你想要的Nuxt模式 (Universal or SPA)\n  4.添加 axios module 以轻松地将HTTP请求发送到您的应用程序中。\n  5.添加 EsLint 以在保存时代码规范和错误检查您的代码。\n  6.添加 Prettier 以在保存时格式化/美化您的代码。\n\n# 启动本地服务\nnpm run dev\n\n```\n\n访问 http://localhost:3000 ，现在我们来看下初始化好的项目目录\n\n注意：nuxt默认会读取pages里面的vue文件，自动生成路由，如需要自定义路由，可在nuxt.config.js中配置对应参数。\n\n### request请求封装\n\n数据和展示层的剥离是有必要的，这也是为什么前端都提倡MV*的设计模式，而对request请求封装是我们第一步要完成的。这里我选了axios作为HTTP请求客户端，axios兼容浏览器端和node端，同时提供了请求拦截、响应拦截等让我们开发更加愉快的功能。\n\n在 `config/index.js` 中写入：\n\n```\nmodule.exports = {\n  IS_RELEASE: true, // true线上，false测试\n\n  BASE_URL: `http://localhost:3000/api`, // 测试\n\n  // BASE_URL: `https://elm.caibowen.net/api`, // 生产\n\n  // IMG_URL: 'http://localhost:9000/', // 测试\n\n  IMG_URL: 'https://easytuan.gitee.io/node-elm-api/public/', // 生产（使用码云Gitee Pages 服务）\n\n  HEADERS: {\n    'Content-Type': 'application/json;charset=UTF-8'\n  },\n\n  TIMEOUT: 12000, // api超时时间\n\n};\n\n```\n\n在 `assets/utils/request.js` 中写入：\n\n```\n\nimport axios from 'axios';\nimport config from '~/config';\nimport { Toast } from 'mint-ui';\n\naxios.defaults.baseURL = config.BASE_URL;\naxios.defaults.timeout = config.TIMEOUT;\naxios.defaults.headers = config.HEADERS;\n\n// 请求拦截器\naxios.interceptors.request.use( request =\u003e {\n  if (!config.IS_RELEASE) {\n    console.log(\n      `${new Date().toLocaleString()}【 M=${request.url} 】P=`,\n      request.params || request.data,\n    );\n  }\n  return request;\n}, error =\u003e {\n  return Promise.reject(error);\n});\n\nexport default async (options = { method: 'GET' }) =\u003e {\n  let isdata = true;\n  if (\n    options.method.toUpperCase() !== 'POST'\n    \u0026\u0026 options.method.toUpperCase() !== 'PUT'\n    \u0026\u0026 options.method.toUpperCase() !== 'PATCH'\n  ) {\n    isdata = false;\n  }\n  const res = await axios({\n    method: options.method,\n    url: options.url,\n    data: isdata ? options.data : null,\n    params: !isdata ? options.data : null,\n  });\n  if (res.status \u003e= 200 \u0026\u0026 res.status \u003c 300) {\n    if (!config.IS_RELEASE) {\n      console.log(\n        `${new Date().toLocaleString()}【接口响应：】`,\n        res.data,\n      );\n    }\n    // 浏览器环境弹出报错信息\n    if(typeof window !== \"undefined\" \u0026\u0026 res.data.code !== 0) {\n      Toast(res.data.msg);\n    }\n    return res.data;\n  }else {\n    if(typeof window !== \"undefined\" \u0026\u0026 res.data.code !== 0) {\n      Toast('请求错误');\n    }\n  }\n\n};\n\n```\n\n最后所有api请求都写进server.js文件，方便统一管理。\n\n### 跨域处理\n\n使用过 `vue` 的同学，肯定知道对于项目中的跨域，`vue-cli` 对 `webpack` 中的 `proxy` 选项进行了一层封装。它暴露出来的是一个叫 `proxyTable` 的选项，是对 `webpack` 中的 `proxy` 和其三方插件 `http-proxy-middleware` 的一个整合。\n\n不幸的 `Nuxt` 中没有 `proxyTable` 这么一个配置项来进行跨域的配置。当然幸运的是，在 `Nuxt` 中你可以直接通过配置 `http-proxy-middleware`  来处理跨域。更幸运的是 `Nuxt` 官方提供了两个包来处理 `axios` 跨域问题。\n\n- [@nuxtjs/axios](https://www.npmjs.com/package/@nuxtjs/axios)\n- [@nuxtjs/proxy](https://www.npmjs.com/package/@nuxtjs/proxy)\n\n首先，进行安装\n\n```shell\nnpm i @nuxtjs/axios @nuxtjs/proxy -D\n```\n\n然后在 `nuxt.config.js` 文件里进行配置\n\n```\n  modules: [\n    '@nuxtjs/axios',\n    '@nuxtjs/proxy'\n  ],\n  proxy: [\n    [\n      '/api',{\n        // target: 'http://localhost:9000',\n        target: 'https://elm-api.caibowen.net',\n        changeOrigin: true,\n        pathRewrite: { '^/api' : '/' }\n      }\n    ]\n  ],\n```\n\n然后你就可以安心使用你的 axios 进行跨域请求了\n\n### 项目部署\n\n到这一步的同学，你得先确保你拥有一个自己的服务器。如果没有的话，赶紧去买一个（我不会和你说AWS和google云有提供免费一年的云服务器试用）\n\n\nOK，文章继续。在进行部署讲解前，我们先看一下开发命令\n\n| 命令            | 描述                                       |\n| ------------- | ---------------------------------------- |\n| dev           | 启动一个热加载的 Web 服务器（开发模式） [localhost:3000](http://localhost:3000/) |\n| start         | 以pm2守护启动一个 Web 服务器 (`nuxt build` 会先被执行)   |\n| generate      | 编译应用，并依据路由配置生成对应的 HTML 文件 (用于静态站点的部署)    |\n\n\n#### 开始部署\n\n\n上传代码到服务器，然后执行命令npm run start 监听3000端口。\n接下来，开始配置你的 nginx （用于端口转发）\n\n```\n server {\n  # 端口，http为 80，如果部署了https请监听 443\n  listen 80;\n  # 域名\n  server_name elm.caibowen.net;\n  # 反向代理\n  location / {\n    proxy_pass http://localhost:3000;\n  }\n}\n```\n\n然后重启 nginx\n\n```\nnginx -s restart\n```\n\n然后你就能在 http://elm.caibowen.net 访问到你的网站啦\n\n\n### 最后\n\n对于 `Nuxt`，在使用层面，是比较简单、好上手的。相对 vue-ssr 来说，它大大的简化了开发的配置，让开发人员可以只需思考业务的开发，而不用太去担心文件的配置。其中 `Nuxt` 通过监听 pages 目录文件变更并自动生成路由更是直接省去了我们平常对于路由的配置。\n\n但是，目前 `Nuxt` 整体还是有待提高的，目前社区相关的三方插件比较有限，市面上相关的参考资料也相对比较少。\n\n不管如何，希望 `Nuxt` 社区可以越来越好吧 ~\n\n# 赞助\n\n如有帮助，欢迎赞助\n\n收到赞助款后，我会及时更新[赞助墙](https://caibowen.net/sponsor)\n\n\u003cimg src=\"screenshots/wechat.jpg\" width=\"200px\" /\u003e \u003cimg src=\"screenshots/alipay.jpg\" width=\"200px\" /\u003e\n\n# 友情链接\n\n[项目后台地址](https://github.com/EasyTuan/node-elm-api)\n\n# License\n\n[GPL](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEasyTuan%2Fnuxt-elm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEasyTuan%2Fnuxt-elm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEasyTuan%2Fnuxt-elm/lists"}