小程序组件化————呱呱二号

小程序组件的使用:

  小程序组件包含四个文件,wxml,json,js,wxss

  1、在json中声明

  {

    "component": true

  }

  2、在wxml中编写组件模板的内容结构,在wxss中编写组件的样式,组件中的样式不会污染页面的样式

  注意事项:在wxss中不应该使用ID选择器和标签选择器以及属性选择器,推荐使用类选择器

  3、js中应该使用Component()构造器,注册组件,

  4、组件的属性,内部数据,将作用于组件的wxml渲染,组件的属性值可以由组件外部传入。

  5、需要使用组件的页面,要先在页面json文件中usingComponents声明,组件名称,组件路径

  {

    "usingComponents": {

      "component-name": "/path/components/component"

    }

  }

  6、在使用组件的页面使用

  <component-name></component-name>

posted @ 2018-01-04 11:45  呱呱二号  阅读(272)  评论(0编辑  收藏  举报