当前位置:主页 > 查看内容

微信小程序 自定义组件

发布时间:2021-05-16 00:00| 位朋友查看

简介:Intro.自定义tabBar的配置 在app.json文件的UsingComponents下注册 tabBar: { borderStyle: white, selectedColor: #333333, color: 999999, list: [ { text: 阅读, pagePath: pages/post/post, iconPath: /images/tab/post.png, selectedIconPath : /images……

Intro.自定义tabBar的配置

在app.json文件的UsingComponents下注册

  "tabBar": {
    "borderStyle": "white",
    "selectedColor": "#333333",
    "color": "999999",
    "list": [
      {
        "text": "阅读",
        "pagePath": "pages/post/post",
        "iconPath": "/images/tab/post.png",
        "selectedIconPath" : "/images/tab/post@highlight.png"

      },
      {
        "text": "电影",
        "pagePath": "pages/movies/movies",
        "iconPath": "/images/tab/movie.png",
        "selectedIconPath" : "/images/tab/movie@highlight.png"
      }
    ]
  }

tabBar的案例可以接触到什么是自定义,但是自定义的程度很小,大部分还是内置完成的。tarBar实例
注意跳转到有选项卡的页面需要使用switchTab

如何创建第一个自定义组件

①根目录下创建components>post>index
②components>post>index.js中定义属性
properties: {
text: {
type: String,//类型
value: ‘123’//默认值
}
}
③在page > xx.json 定义名称
“usingComponents”: {
“c-post”:"/components/post/index"
}
④在page > xx.wxml中使用
⑤components > post > index.wxml
{{text}}

自定义组件属性

自定义的属性 text 也可以做数据绑定
快速自定义属性时,无法自定义默认值
properties: {
text: String // 也可以为Number(默认值为0)、Object、Boolean(默认值为false)
}

把原来post页面的文章部分作为一个组件,wxml和wxss复制到组件对应下wxml和wxss下

为什么index.wxml(组件的)打印data和posts.wxml不一样:
posts里面data是自带的,所以不用,直接去打印res。然而index是接受到res放进properties


;原文链接:https://blog.csdn.net/weixin_46728068/article/details/115474628
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:安装Gin核心步骤(win7) 下一篇:没有了

推荐图文


随机推荐