如何注册组件

组件编写

编写组件和 vue 开发文档一致,我们拓展了 vue的生命周期钩子函数,支持 wx 小程序生命周期钩子

组件注册

目前 360 小程序仅支持 组件局部注册,不支持 组件全局注册其他请参考 vue 组件开发文档

  1. // 方式1
  2. import ComponentB from '../common/ComponentA.vue'
  3. // 方式2 需在 pages 中注册过 详细参考[文件后缀支持]
  4. import ComponentA from '../common/search/index.js'
  5. Page({
  6. name: "Home",
  7. components: { ComponentA, ComponentB },
  8. ...

文件后缀支持

  • .vue
  • .js该 js 文件对应路径需要在 app.json pages 中注册。示例如下:
  1. {
  2. "pages": [
  3. "pages/home/index",
  4. "pages/more/index",
  5. "pages/common/search/index"
  6. ],
  7. ...
  8. }