Objective
Multi-page applications are more structured than simple pages, because simple pages use router and are too cumbersome. This scaffold was developed for such a scenario.
Using scaffolding with Hbuilder is also a quick way to develop Android and iOS apps with Vue.
The main features of this paper:
- Webpack4
- Multi-page
- Cross-domain proxy proxy
- Vconsole Mobile debugging, developer tools on the phone
- Es6/es7 Babel Conversion
Project address GitHub User's manual
MogoH5+is a VUE multi-page Scaffolding tool that combines h5+ to quickly develop Android and Apple apps.
This scaffold can also be used as a reference item for multi-page Web pages, even if the hbuilder is not suitable for packaging into an APP.
Characteristics
支持 Npm 生态
支持 vue 语法,以及 vue 生态,比如 vux,mint,vant
支持 ES6/ES7 语法
使用 VConsole 调试
VSCode 友好
局域网便捷调试
兼容部分 mui 语法
These features are not really new, but are not available in Hbuilder alone.
Get started quickly
Download the project directly and then customize the package to suit your needs, and finally package with the Hbuilder cloud to build your APP.
This article comes with a case of several interfaces developed using Vantui, and if you like other UIs you can also replace them with other UIs.
// 1.安装模块npm i // or yarn// 2.调试npm start // 将manifest.json 的`页面入口` 修改成 http://your_ip:8082/// 3.打包npm run build
Use
Mainly how to use mogoh5+ to do formal development, in the development process must abide by the directory rules , otherwise there will be unexpected errors.
Directory structure
.├── docs // 文档├── index.html // 入口模板├── jsconfig.json //js配置├── manifest.json //hbuilder 入口文件├── src │ ├── components //组件文件夹│ │ └── List.vue //组件│ ├── index.js //主页入口文件│ ├── index.vue // 主页vue文件│ ├── page // 页面│ └── utils // 工具├── unpackage // hbuilder 构建目录│ └── res└── webpack.config.js //webpack配置目录
New Page
If we want to create a new page with a name called list the product list, we're going to ./src/page/goods create a new list.js and list.vue two files. list.js As a multi-page entry, list.vue scaffolding comes with several pages for reference.
Follow the relative path principle, if src you access this page is the ./goods/list.html !!! suffix must be.html
New Component
Components are placed in a ./src/components directory, and if the components are large, you can create your own. For example, the Logo component used in the demo can serve as a reference.
New Tool Library
The tool library ./src/utils mainly puts some common functions, such as requests, open webview, payment, sharing and so on. The demo encapsulates some functions from the MUI 自定义事件 , such as webview . These functions can be used as a reference.
`common.js` 是每个页面都需要加载的一个 js,里面加载了`fastclick`和`vconsole`.如果全局需要加统计,全局执行的函数,可以放在这个文件里面.`./src/utils` 做了 `alias`别名,可以 直接这样加载 `import common from "Utils/common"`.
Send Request Request Library
The demo request uses the axios same kind of library that you would like to encapsulate yourself.
The common request Library has fetch , request , SuperAgent , jquery-ajax .
Cross-domain
As a result, the npm start Debug Web page is hung on the local area network and as Hbuilder 页面入口 , so it appears on request 跨域 .
./build.jsusing a local agent in, change the following to the https://api.douban.com business domain name you use.
Proxy: {"/api": {Name "Doubanapi", //own name target: "https ://api.douban.com ", pathrewrite: {" ^/api ": changeorigin: true, secure: false}, "/baidu_api": {name:" Baiduapi "//own name target: " https://api.baidu.com ", pathrewrite: {" ^/api ": Span class= "hljs-string" ""}, changeorigin: true, secure: false}, ...}
If there are more business domain names you can continue to proxy Add.
Only when the development of the cross-domain problem, the packaged file URL will be replaced by the proxy URL, so send the request must add a nameDOUBANAPI
request({ url: DOUBANAPI + "/bookList"});
Debugging
Debugging in Hbuilder will have many problems, such as:
- Cannot print directly
数组 , 对象 it needs to be converted into a string.
- Even if
webview调试 you use it, you still can't print the array, and it's very inconvenient to use on your Mac.
Use VConsole , debugging problems are basically out of hbuilder, the use of the VConsole main advantages are as follows
- You can print an array, an object
- Can view requests, cookie,localstorage
Systempage loading speed can be seen in the column
- can view elements
It's basically a simplified one 开发者工具栏 , and it's very easy for debugging.
Packaged
npm run build
After running the command there will be a dist directory, inside the compressed static file.
Hbuilder Release Package
Before using Hbuilder to make the installation package, please 入口文件 change it to dist/index.html . Then you can pack it with peace of mind.
Compatible with Mui.js
The problem with MUI partial functions has been ported in some of the functions Utils , and will be migrated slowly in future updates.
Scaffolding tools for fast app development with Vue