前端之美-小程序

支付宝小程序开发体验

2018-02-06  本文已影响372人  勇往直前888

在使用过程中想到一点记录一点,只是个人感想。

将图上那个小红色回退,删除掉,保存,不再出现就可以了

page {
  background-color: #f8f8f8;
  border: 1px solid rgba(0,0,0,0);
  box-sizing: border-box;
}

其中的box-sizing: border-box;表示盒模型中,将paddingborder都计入width、height,这是推荐的做法
box-sizing

.item {flex: 1;}
.item {
    flex-grow: 1;
    flex-shrink: 1;
    flex-basis: 0%;
}

弹性盒模型在小程序中用得比较多,需要重点看看。
flex设置成1和auto有什么区别

rpx(responsive pixel)可以根据屏幕宽度进行自适应。规定屏幕宽为750rpx。如在 iPhone6 上,屏幕宽度为375px,共有750个物理像素,则750rpx = 375px = 750物理像素,1rpx = 0.5px = 1物理像素。

这段话是手册中的,不是非常理解。印象中iPhone6的宽度是375×667点,对应到UI的分辨率是750×1334 px

小程序手册样式一节
iPhone/iPad/Android UI尺寸规范

<!--
  index: int
  msg: string
  time: string
-->
<template name="msgItem">
  <view>
    <text> {{index}}: {{msg}} </text>
    <text> Time: {{time}} </text>
  </view>
</template>

使用模板:

<template is="msgItem" data="{{...item}}"/>
Page({
  data: {
    item: {
      index: 0,
      msg: 'this is a template',
      time: '2016-09-15'
    }
  }
})

现在,想要修改msg的值,如果只是像下面那样写,那么,index、time两个字段就会被清空。

this.setData({
   item: {
      msg: 'new template',
   }
}});

可以考虑下面的写法,能够达到目的:

const newItem = this.data.item;
newItem.msg = 'new template';
this.setData({
  item: newItem,
});

上面这种方式会带来性能问题,不是很推荐,也可以考虑下面的方法:

this.setData({
  item.msg: 'new template',
});

目前来看,还是模式一比较方便;当然用模式二也是可以的。

上一篇 下一篇

猜你喜欢

热点阅读