康巴易测肤/伤疤uniapp小程序类
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.4KB

1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # uni-read-pages
  2. ![coverage](https://img.shields.io/badge/coverage%20-98%25-green) ![npm](https://img.shields.io/badge/npm%20-v2.6.11-blue) ![license](https://img.shields.io/badge/license-MIT-red) ![size](https://img.shields.io/badge/size-1.48%20kb-yellowgreen)
  3. 通过 [vue.config.js](https://cli.vuejs.org/zh/config/) 配合此库,可以随心所欲的读取 `pages.json` 下的所有配置
  4. ## 安装
  5. 您可以使用 `Yarn` 或 `npm` 安装该软件包(选择一个):
  6. ##### Yarn
  7. ```sh
  8. yarn add uni-read-pages
  9. ```
  10. ##### npm
  11. ```sh
  12. npm install uni-read-pages
  13. ```
  14. ## 开始
  15. 配置 `vue.config.js` 通过 `webpack` 注入全局变量 [查看文档](https://www.webpackjs.com/plugins/define-plugin/)
  16. #### 配置 `vue.config.js`
  17. ```js
  18. //vue.config.js
  19. const TransformPages = require('uni-read-pages')
  20. const tfPages = new TransformPages()
  21. module.exports = {
  22. configureWebpack: {
  23. plugins: [
  24. new tfPages.webpack.DefinePlugin({
  25. ROUTES: JSON.stringify(tfPages.routes)
  26. })
  27. ]
  28. }
  29. }
  30. ```
  31. 借助`webpack.DefinePlugin` 轻松注入全局变量。`ROUTES` 及可全局使用
  32. #### 使用
  33. ```js
  34. // xxx.vue
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. title: 'Hello'
  40. }
  41. },
  42. onLoad() {
  43. console.log(ROUTES)
  44. },
  45. }
  46. </script>
  47. ```
  48. ## API
  49. #### options
  50. ```js
  51. //默认值
  52. const CONFIG={
  53. cli:false, //当前是否为脚手架初始化的项目
  54. includes:['path','aliasPath','name'] //需要获取包涵的字段
  55. }
  56. ```
  57. #### Instance method
  58. * **getPagesRoutes**
  59. * 通过读取 `pages.json` 文件 生成直接可用的routes
  60. * **parsePages(pageCallback, subPageCallback)**
  61. * 单条page对象解析
  62. * **resolvePath(dir)**
  63. * 解析绝对路径
  64. #### Instance attr
  65. * **CONFIG**
  66. * 当前配置项
  67. * **webpack**
  68. * 当前工程下需要用到 `webpack`
  69. * **uniPagesJSON**
  70. * 当前 `uni-app` 内置对象,可以通过此属性调用一些内置方法
  71. * **routes**
  72. * 通过 **includes** 解析后得到的路由表 **可直接使用**
  73. #### getter
  74. * **pagesJson**
  75. * 获取所有 `pages.json` 下的内容 返回 `json`
  76. #### uniPagesJSON method
  77. * getMainEntry()
  78. * getNVueMainEntry()
  79. * parsePages (pagesJson, pageCallback, subPageCallback)
  80. * parseEntry (pagesJson)
  81. * getPagesJson()
  82. * parsePagesJson (content, loader)
  83. #### uniPagesJSON attr
  84. * pagesJsonJsFileName //默认值 pages.js