微信小程序开发实战-第四周

news/2024/7/20 2:46:56 标签: 小程序, javascript, html5, css3

第四周

什么是“剥夺“函数return能力

使用回调函数的方式无法return

点赞数据提交

page\classic\classic.js中定义onLike函数

javascript">onLike: function (event) {
    console.log(event)
    let behavior = event.detail.behavior
  }

拿到当前like组件的状态

向服务器提交状态数据,提交状态数据放到models

models中新建like.js

javascript">import {HTTP} from '../util/http.js'

class LikeModel extends HTTP {
like(behavior, artID, category) {
      let url = behavior === 'cancel' ? 'like/cancel' : 'like'
      this.request({
        url: url,
        method: 'POST',
        data: {
          art_id: artID,
          type: category
        },
        success: (data) => {
          console.log(data)
        }
      })
    }
}

export {LikeModel}
点赞API接口说明

http://bl.7yue.pro/dev/like.html#id2

Parameters:

  • art_id: 点赞对象,例如你想对电影进行点赞,那这个参数就是电影的id号
  • type:点赞类型分为四种:100 电影 200 音乐 300 句子 400 书籍

判断是否为空,为空则不执行之后的代码

javascript">params.success && params.success(res.data)

组件的生命周期函数

https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html

期刊组件epsoide

components下新建epsoide组件

<view class="container">
  <view class="index-container">
    <text class="plain">No.</text>
    <text class="index">{{_index}}</text>
    <view class="vertical-line"></view>
  </view>
    <view class="date"> 
     <text class="month">{{month}}</text> 
    <text class="year">{{year}}</text>
   </view>  
</view>
.index{
  font-size:30px;
  /* line-height:20px;  */
  font-weight:800;
  margin-right:7px;
}

.vertical-line{
  margin-right:7px;
  height:22px;
  border-left:1px solid black;
}

.plain{
  font-size:16px;
}

.container{
  display:inline-flex;
  flex-direction: row;
  line-height: 30px;
  /* justify-content: flex-end; */
   /* align-items: baseline;       */
}

.index-container{
  display:flex;
  flex-direction: row;
  align-items: baseline;      
}

.date{
  display: flex;
  flex-direction: column;
  justify-content: center; 
  /* align-items: baseline; */
   /* line-height:30px;   */
}

.month{
  font-size:12px;
  line-height:12px; 
  padding-bottom: 2px; 
  margin-right:2rpx;
  /* padding-right:4rpx; */
}

.year{
  font-size:10px;
  line-height:10px; 
  padding-bottom:3px;   
}

然后引用组件

data中的数据
javascript">  data: {
      months:[
        '一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月',
        '十二月'
      ],
      year:Number,
      month:String,
      _index:String
  }
解决序号index的问题
javascript">properties: {
    index:{
      type: Number,
      observer:function(newVal, oldVal, changedPath){
        // 如果index小于10就在前面加0
        if (newVal < 10) {
          this.setData({
            _index: '0' + newVal
          })
        }
      }
    }
  }

propertiesdata的数据都指向相同的JavaScript对象

不要在observe中修改自身属性

获取当前日期

ready生命周期函数:在组件在视图层布局完成后执行

通过setData来将数字月份和文字进行匹配显示出来

javascript">  ready:function(){
    let date = new Date()
    let month = date.getMonth()
    let year = date.getFullYear()
    this.setData({
      month:this.data.months[month],
      year:year
    })
  }
最终代码

classic.wxml

<view class="header">
    <v-epsoide class="epsoide" index="{{classic.index}}" />
    <v-like class="like" bind:like="onLike" like="{{classic.like_status}}" count="{{classic.fav_nums}}"/>
</view>
<v-movie img="{{classic.image}}" content="{{classic.content}}"></v-movie>

classic.wxss中设置如下样式

.header {
    width: 100%;
    display: flex;
    flex-direction: row;
    height: 50px;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid #f5f5f5;
    border-bottom: 1px solid #f5f5f5;
}

.container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.like {
    margin-right: 30rpx;
    margin-top: 12rpx;
}

.like-container {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-right: 30rpx;
}

.share-btn {
    margin-top: 28rpx;
    margin-left: 10rpx;
}

.share {
    /* padding:10rpx; */
    width: 40rpx;
    height: 40rpx;
}

.navi {
    position: absolute;
    bottom: 40rpx;
}

.epsoide {
    margin-left: 10px;
    margin-top: 7px;
}

image-20200408170203450


http://www.niftyadmin.cn/n/1849304.html

相关文章

iphone怎样关闭副屏_iOS13.4.5B1发布,iOS13.3.1验证通道关闭,iPhone9的存在已确定

iOS 13.4.5beta1发布4月1日凌晨&#xff0c;也就是愚人节凌晨&#xff0c;苹果对外发布了iOS 13.4.5beta1版本&#xff0c;这次是直接绕过了iOS 13.4.1&#xff0c;这可能是在之前都已经进入了iOS 13.4.1的开发项目&#xff0c;只是在iOS 13.4正式版发布之后&#xff0c;发现了…

UUID是什么?

UUID就是Universal Unique IDentifier的缩写&#xff0c;它是一个128位&#xff0c;16字节的值&#xff0c;并确保在时间和空间上唯一。它是把硬件地址、时间以及随机数结合在一起&#xff0c;来确保其唯一性的。一般情况下&#xff0c;生成算法用计算机网卡的地址和一个60位的…

delphi 面试题

为什么80%的码农都做不了架构师&#xff1f;>>> 一、 Delphi基础 1、Delphi 内置类型 string 和 WideString 的区别。 答&#xff1a; string 即 UnicodeString&#xff0c;8 位&#xff08;ANSI &#xff09;字符 WideString 类型是动态分配的、由 16 位 Unicode…

微信小程序开发实战-第五周

第五周 navi组件 新建navi导航组件 导入相应的图片素材文件 设置组件属性列表 title&#xff1a;当前期刊标题 first&#xff1a;指定当前期刊是否为第一期 latest指定当前期刊是否为最后一期 设置图片url disLeftSrc: images/triangle.disleft.png, highLeftSrc: ima…

打开新窗口让他状态在加载中_提高产品状态可见性的4种方法

如何让用户时刻清楚自己所处的状态、并对当前的目标及去向有所了解呢&#xff1f;这里将提供四种反馈方法来提高产品状态的可见性。状态可见性原则是人机交互学博士尼尔森发表的“十大可用性原则”中的其中一条。通过传达系统的当前状态&#xff0c;让用户感觉到产品具有可控性…

微信小程序开发实战-第六周

第六周 加入缓存系统 获取期刊时先到缓存中查找&#xff0c;如果能找到就读取&#xff0c;不能就向服务器发送请求&#xff0c;然后再次写入缓存中 所有期刊在缓存有一个key&#xff0c;确定key&#xff0c;代表一个期刊和表示是哪一期期刊 定义一个私有方法_fullKey来生成ke…

python求最大字符串_【python】实例-python实现两个字符串中最大的公共子串

由于python中的for循环不像C这么灵活&#xff0c;因此该用枚举法实现该算法&#xff1a;C"abcdefhe"D"cdefghe"m0nlen(C)E[]b0while(min-mwhile(i>0):E.append(C[m:mi])i-1m1for x in E:a0if x in D:alen(x)cE.index(x)if a > b:#保存符合要求的最长…

RHEL5+nginx+fastcgi+php实现lnmp环境

RHEL5nginxfastcgiphp实现lnmp环境准备kill本机的80端口nginx-1.5.1.tar.gz安装包 www.wiki.nginx.orgphp运行管理脚本###!/bin/sh## php-cgi - php-fastcgi swaping via spawn-fcgi## chkconfig: - 85 15# description: Run php-cgi as appserver# processname: php-cgi# …