小程序开发过程遇到的散碎知识

本文总结了小程序开发中的几个关键知识点,包括view的居中布局、自定义组件调用、模板字符串的使用、WXS在设置image src中的应用以及弹性布局的详细解释。同时,还讨论了在开发中遇到的View尺寸设置无效的异常问题及其解决方案。
摘要由CSDN通过智能技术生成

框架

一、view居中

.example{
      display: flex;
      justify-content: center;  /*水平*/
      align-items: center; /*垂直*/
  }

wxml:
<view class="parent">
  <view class="child">text1</view>
  <view class="child">text2</view>
</view>

wxss:
.parent {
  width: 60%;
  height: 60%;
  border: 1rpx solid red;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column; //子view排序方向
}

注意:parent  的配置,是所有子view居于父view的居中,即如果想配置view相对于父view的居中,需要配置父view的css文件,而非 view本身。

二、自定义组件Component

调用组件内方法:通过id 初始化组件对象  调用组件内函数

自定义组件tabpage.js
/**
 * 组件的方法列表
 */
methods: {
    getProjectDatas(cid, page = 1) {
      wx.request({
        url: domain + `/project/list/${page}/json`,
        data: {
          cid: cid,
        },
        success:res=>{
          // console.log(res.data.data.datas)
          this.setData({
            projectList:res.data.data.datas
          })

          // console.log(this.data.projectList)
        }
      })
    },
  },



调用页面 
index.wxml
 <tab-page id="tab-page" navData="{
  {tabItem}}"></tab-page>

index.js
this.selectComponent("#tab-page").getProjectDatas(this.data.navDataList[cur]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值