基础知识
分包
easycom机制
传统vue组件,需要安装、引用、注册,三个步骤后才能使用组件。easycom将其精简为一步。 只要组件安装在项目的components目录下,并符合components/组件名称/组件名称.vue目录结构。就可以不用引用、注册,直接在页面中使用。 如下:
"easycom": {
"autoscan": true,
"custom": {
"^uni-(.*)": "@/components/uni-$1.vue", // 匹配components目录内的vue文件
"^vue-file-(.*)": "packageName/path/to/vue-file-$1.vue" // 匹配node_modules内的vue文件
}
}
<template>
<view class="container">
<uni-list>
<uni-list-item title="第一行"></uni-list-item>
<uni-list-item title="第二行"></uni-list-item>
</uni-list>
</view>
</template>
<script>
// 这里不用import引入,也不需要在components内注册uni-list组件。template里就可以直接用
export default {
data() {
return {
}
}
}
</script>
应用生命周期
- onLaunch 初始化完成时触发(全局只触发一次)
- onShow 启动 或 从后台进入前台显示
- onHide 从前台到后台触发
- onError 报错时触发
- onUniNViewMessage nvue 对页面发送数据进行监听
- onUnihandleRejection 对未处理的promise 拒绝事件监听函数
- onPageNotFound 页面不存在监听
- onThemeChange 监听系统主题变化