{"id":13536408,"url":"https://github.com/RalfZhang/Vdo","last_synced_at":"2025-04-02T03:30:45.453Z","repository":{"id":101897572,"uuid":"82712247","full_name":"RalfZhang/Vdo","owner":"RalfZhang","description":"A Vue.js project for douban.com","archived":false,"fork":false,"pushed_at":"2018-08-10T07:21:31.000Z","size":4155,"stargazers_count":273,"open_issues_count":0,"forks_count":60,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-03T01:33:11.490Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://vdo.ralfz.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RalfZhang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-02-21T18:17:28.000Z","updated_at":"2024-05-13T09:21:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"2769a7ca-887d-4704-a776-4585000c9ce4","html_url":"https://github.com/RalfZhang/Vdo","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/RalfZhang%2FVdo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RalfZhang%2FVdo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RalfZhang%2FVdo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RalfZhang%2FVdo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RalfZhang","download_url":"https://codeload.github.com/RalfZhang/Vdo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246750849,"owners_count":20827790,"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":[],"created_at":"2024-08-01T09:00:38.732Z","updated_at":"2025-04-02T03:30:44.985Z","avatar_url":"https://github.com/RalfZhang.png","language":"JavaScript","funding_links":[],"categories":["Demo示例"],"sub_categories":[],"readme":"# 微豆 Vdo\n\n[![Build Status](https://travis-ci.org/RalfZhang/Vdo.svg?branch=master)](https://travis-ci.org/RalfZhang/Vdo)\n\n一个使用 Vue.js 与 Material Design 重构 [豆瓣](http://www.douban.com) 的项目。  \n\n项目网站 http://vdo.ralfz.com/\n\n![GIF 图片](/static/md/example.gif)\n\n\n# 快速使用  \n\n``` bash\n# 克隆项目到本地\ngit clone https://github.com/RalfZhang/Vdo.git\n\n# 安装依赖\nnpm install\n\n# 在 localhost:8080 启动项目\nnpm run dev\n```\n\n# 教程  \n\n\n## 安装 vue-cli 脚手架  \n\n\n运行如下命令，即可创建一个名为 my-project 的 vue 项目，并且通过本地 8080 端口启动服务   \n    \n``` bash\nnpm install -g vue-cli\nvue init webpack my-project\ncd my-project\nnpm install\nnpm run dev\n```\n\n\n在运行 `vue init webpack my-project` 后，会依次要求输入以下配置内容  \n- 项目名称\n- 项目描述\n- 作者\n- 选择 Vue 构建：运行+编译 或 仅运行时\n- 是否安装 vue-loader\n- 是否使用 ESLint\n    - 如果是，请选择模式：标准模式、AirBNB 模式、自定义\n- 是否使用 Karma + Mocha 的单元测试\n- 是否使用 Nightwatch e2e 测试  \n\n![Image](/static/md/vue-init.png)\n\n\n\n安装完成后，即可看到以下文件结构：\n\n```\n.\n|-- build                            // 项目构建相关代码\n|   |-- build.js                     // 生产环境构建代码\n|   |-- check-version.js             // 检查 node、npm 等版本\n|   |-- dev-client.js                // 热重载相关\n|   |-- dev-server.js                // 构建本地服务器\n|   |-- utils.js                     // 构建工具相关\n|   |-- webpack.base.conf.js         // webpack 基础配置（出入口和 loader）\n|   |-- webpack.dev.conf.js          // webpack 开发环境配置\n|   |-- webpack.prod.conf.js         // webpack 生产环境配置\n|-- config                           // 项目开发环境配置\n|   |-- dev.env.js                   // 开发环境变量\n|   |-- index.js                     // 项目一些配置变量（开发环境接口转发将在此配置）\n|   |-- prod.env.js                  // 生产环境变量\n|   |-- test.env.js                  // 测试环境变量\n|-- src                              // 源码目录\n|   |-- components                   // vue 公共组件\n|   |-- store                        // vuex 的状态管理\n|   |-- App.vue                      // 页面入口文件\n|   |-- main.js                      // 程序入口文件，加载各种公共组件\n|-- static                           // 静态文件，比如一些图片，json数据等\n|-- test                             // 自动化测试相关文件\n|-- .babelrc                         // ES6语法编译配置\n|-- .editorconfig                    // 定义代码格式\n|-- .eslintignore                    // ESLint 检查忽略的文件\n|-- .eslistrc.js                     // ESLint 文件，如需更改规则则在此文件添加\n|-- .gitignore                       // git 上传需要忽略的文件\n|-- README.md                        // 项目说明\n|-- index.html                       // 入口页面\n|-- package.json                     // 项目基本信息\n.\n```\n\n## ESLint 配置  \n\nESLint 配置在根目录的 `.eslintrc.js` 里。  \n正常情况下，ESLint 报错是因为你的代码不符合现有的 ESLint 规范。\n如果你的情况实在不想被 ESLint 报错，我举出两个解决方案，来处理 ESLint 报错问题。  \n\n注：本例使用 AirBNB ESLint 规则。  \n例：通过 `npm run dev` 启动服务，打开 `./src/main.js`，添加一句 `console.log('abc')`，结果如下：\n```js\nimport Vue from 'vue';\nimport App from './App';\nimport store from './vuex/store';\n/* import router from './router';*/\n\n// 添加此句\nconsole.log('abc')\n\n/* eslint-disable no-new */\nnew Vue({\n  el: '#app',\n  /* router,*/\n  template: '\u003cApp/\u003e',\n  components: { App },\n  store,\n});\n```\n注：为做演示，句末未添加分号。  \n\n保存 `main.js` 文件后，页面与终端均提示如下错误：  \n```bash\n ERROR  Failed to compile with 1 errors \n error  in ./src/main.js\n  ⚠  http://eslint.org/docs/rules/no-console  Unexpected console statement\n  C:\\Users\\Ralf\\Documents\\code\\ralfz\\vue\\test\\vue02\\src\\main.js:8:1\n  console.log('abc')\n   ^\n  ✘  http://eslint.org/docs/rules/semi        Missing semicolon\n  C:\\Users\\Ralf\\Documents\\code\\ralfz\\vue\\test\\vue02\\src\\main.js:8:19\n  console.log('abc')\n                     ^\n✘ 2 problems (1 error, 1 warning)\nErrors:\n  1  http://eslint.org/docs/rules/semi\nWarnings:\n  1  http://eslint.org/docs/rules/no-console\n @ multi ./build/dev-client ./src/main.js\n```\n以上输出表明出现两个问题：  \n\n1. 警告：不允许 console 语句。  \n2. 错误：句末未加分号。\n\n解决问题 1  \n- 在 `.eslintrc.js` 文件中的 `rules` 键名下添加`'no-console': 'off',`，即关闭 console 警告。\n\n解决问题 2  \n- 你可以选择继续在 `.eslintrc.js` 文件中添加关闭句末分号判定的规则。\n- 或者，也可以把 `package.json` 文件中的 `script` 下的 `lint` 命令改为 `\"lint\": \"eslint --fix *.js *.vue src/* test/unit/specs/* test/e2e/specs/*\"` 同时，将 `/build/webpack.base.conf.js` 里 `formatter: require('eslint-friendly-formatter')` 后添加 `, fix: true` 即自动修复。（值得注意的是，自动修复不能解决所有问题，有时也不甚完美，可以多试几次体会下 fix 的效果。）\n\n做完更改后，重新运行 `npm run dev` 即可看到无问题报告，并且 `console` 语句后已经自动加上了分号。\n\n\n## 静态页面开发  \n\n此时，浏览器应该已经打开了 localhost:8080 页面。  \n\n在此情况下，请尝试更改 `/src/App.vue` 和 `/src/components/Hello.vue` 文件中`\u003ctemplate\u003e`标签内的内容，保存后即可立即看到浏览器页面已自动更新了你做出的改动。  \n\n接下来，你需要去阅读并学习 [Vue.js 教程页面](https://cn.vuejs.org/v2/guide/)，务必熟悉 **基础** 部分的内容，掌握 **[组件](https://cn.vuejs.org/v2/guide/components.html)** 章节。  \n\n熟悉之后，便可以完成基础的静态页面（或者说是组件）设计工作。  \n\n本项目使用了基于 Vue 2.0 和 Material Desigin 的 UI 组件库 [Muse-UI](https://museui.github.io/)。\n\n提示：`./src/components` 文件夹多用于保存公用组件。至于页面组件，推荐在新建 `./src/view` 文件夹后存放于此。\n\n\n## vue-router 2 使用\n\n当一个个静态组件完成后，需要按照路由组织这些组件文件。  \n\n请前往 [vue-router 2 介绍](https://router.vuejs.org/zh-cn/) 阅读 __基础__ 部分教程，并可以边阅读边配置路由。  \n\n路由文件是 `./src/router.index.js` 。  \n\n本项目中使用了 [HTML5 History 模式](https://router.vuejs.org/zh-cn/essentials/history-mode.html)，路由配置比较简单，可以参考。  \n\n\n## API 请求转发配置\n\n至此，你应该已经完成了所有的静态页面的工作，接下来我们准备搭建请求，为后面的 xhr 请求做好准备。  \n\n1. 打开 `http://api.douban.com/v2/movie/in_theaters` 查看接口数据，留意此地址。  \n\n2. 在 `./config/index.js` 中的 `proxyTable` 配置代理：  \n\n    ```js \n    proxyTable: {\n        '/api': {\n            target: 'http://api.douban.com/v2',\n            changeOrigin: true,\n            pathRewrite: {\n                '^/api': ''\n            }\n        }\n    }\n    ```  \n\n3. 重新启动 `npm run dev`，打开 `localhost:8080/api/movie/in_theaters` 查看结果是否与直接请求豆瓣 API 相同。  \n\n4. 本应该使用了以下 API：  \n    - `/v2/movie/search?q={text}` 电影搜索api；  \n    - `/v2/movie/in_theaters` 正在上映的电影；  \n    - `/v2/movie/coming_soon` 即将上映的电影；  \n    - `/v2/movie/subject/:id` 单个电影条目信息。  \n\n\u003e 更多请参考 [豆瓣电影 API](https://developers.douban.com/wiki) 文档。    \n\n这样我们就可以在应用中调用 `/api/movie/in_theaters` 来访问 `http://api.douban.com/v2/movie/in_theaters`，从而解决跨域的问题。\n\n## 使用 axios \n\naxios 库使用起来相当简单。  \n\n你可以在单个组件中尝试引入并调用：  \n```javascript\nimport axios from 'axios';\naxios.get('/v2/movie/in_theaters', { 'city': '广州' })\n    .then((result) =\u003e {\n        console.log(result);\n    });\n```\n这里，可以用返回的 `result` 去更新 `data(){ }` 中 `return` 的数据。  \n\u003e 更多 axios 用法请参考 [文档](https://github.com/mzabriskie/axios#example)\n\n## 使用 Vuex 并分离代码  \n\n为了试代码更加结构化，我们应当将数据请求和视图分离。  \n\n这一节中，我们有两个任务要做：  \n\n1. 分离数据请求层逻辑。  \n2. 使用 Vuex 管理状态。   \n\n将二者放到同一节中主要是因为二者再同一目录下，我们来查看 `./store` 文件夹的结构：\n```\n.\n|-- store                          // 数据处理根目录\n|   |-- movies                     // 单个电影模块文件夹\n|   |   |-- api.js                 // 电影模块对外开放的接口\n|   |   |-- module.js              // Vuex 模块\n|   |   |-- type.js                // Vuex 操作 key\n|   |-- base.js                    // 基础方法\n|   |-- store.js                   // Vuex 入口\n.\n```\n针对第一个任务：\n- `base.js` 存放封装的基础请求函数  \n- `**/api.js` 存放该模块下公开的请求函数  \n\n针对第二个任务，我们需要先了解 Vuex。  \n\n请查看 [Vuex 文档](https://vuex.vuejs.org/zh-cn/)，了解其 **核心概念**。  \n\n\u003eVuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态，并以相应的规则保证状态以一种可预测的方式发生变化。Vuex 也集成到 Vue 的官方调试工具 devtools extension，提供了诸如零配置的 time-travel 调试、状态快照导入导出等高级调试功能。  \n\n其实在我看来，Vuex 相当于某种意义上设置了读写权限的全局变量，将数据保存保存到该“全局变量”下，并通过一定的方法去读写数据。（希望这能帮助你理解 Vuex）\n\n为了方便模块化管理：  \n- 我将 `store.js` 作为入口文件，去挂载各个模块；  \n- `/movies/`文件夹下为电影相关的模块；  \n- `/movies/moudule.js` 为电影模块的主要 Vuex 文件；  \n- `/movies/type.js` 为[使用常量替代 Mutation 事件类型](https://vuex.vuejs.org/zh-cn/mutations.html)的实现。  \n\n到此便完成了所有开发上的基础问题。\n\n## 发布\n\n1. 运行 `npm run build`，即可在生成的 `/dist` 文件夹下看到所有文件。  \n2. 将文件复制到你的服务器上某个目录（我的是`/var/www/Vdo/dist`），按照下一节配置 Nginx 即可\n\n提示：可以使用 `scp` 命令将本地文件拷贝至服务器，例如 `scp -P 20 -r dist user@host:/target/location`\n\n\n## 附：配置与开启 Nginx \n注：以下以 CentOS 为例  \n1. 服务器安装 Nginx：`yum install nginx`  \n2. 服务器打开 `/etc/nginx/conf.d/default.conf`  \n3. 替换全文为本项目 `/doc/nginx.conf` 文件中的内容  \n4. 服务器运行 `nginx`    \n\n提示：   \n\n1. `403 Forbidden` 错误可能是由于文件和文件夹权限引起的，请用 `chmod` 把存放 `index.html` 的所有路径上的文件夹权限设置为 755，并将 `index.html` 文件权限设置成 644 即可。  \n2. 更改 Nginx 配置文件后，可以使用 `nginx -s reload` 命令刷新。  \n\n# 结语  \n\n至此，主体工作已经完成。  \n\n欢迎 Star 本项目。\n\n\n# 感谢\u0026参考\n- https://github.com/superman66/vue2.x-douban\n- http://blog.guowenfh.com/2016/03/24/vue-webpack-01-base/\n- https://github.com/mzabriskie/axios\n- https://museui.github.io/\n- https://vuejs-templates.github.io/webpack/\n\n# License  \n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRalfZhang%2FVdo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRalfZhang%2FVdo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRalfZhang%2FVdo/lists"}