微信小程序04---头像上传、瀑布流、下拉刷新、触底加载更多、分包

目录

一、头像上传

1、选择图片   wx.chooseImage()

2、上传文件   wx.uploadFile()

二、瀑布流+下拉刷新+触底加载

三、分包加载

什么是分包

为什么要使用分包

如何使用分包

配置

分包的限制

独立分包

分包预加载

一、头像上传

1、选择图片   wx.chooseImage()

        其中count未上传的个数

2、上传文件   wx.uploadFile()

        在上传文件时要注意:

                ①文件上传地址的域名要在微信开发平台进行设置

                ②头部要携带cookie

                ③filePath 属性是从wx.chooseImage()中获取的,所以这两个API常常在一起使用

                ④name属性是更改头像接口上传文件的字段名

                ⑤头部默认为 multipart/form-data 格式

                ⑥上传地址 url 属性值为接口地址

更改头像:
	
	// 上传图片
	    wx.chooseImage({
	      count: 1,
	      success: (res) => {
	        console.log(res);
	        // 更改头像
	        wx.uploadFile({
	          header: {
	            'cookie': wx.getStorageSync('cookie')
	          },
	          filePath: res.tempFilePaths[0],
	          name: 'avatarfile',
	          url: 'https://showme2.myhope365.com/api/system/user/profile/update/avatar/nos',
	          success: (res1) => {
	            console.log(res1);
	            wx.showToast({
	              title: '更改成功',
	            })
	          },
	          complete: () => {
	            getUserInfo().then(res3 => {
	              this.setData({
	                userInfo: res3.data.data,
	                isLoading: false
	              })
	            })
	          }
	        })
	      },
	      fail: () => {
	        wx.showToast({
	          icon: "error",
	          title: '取消更改',
	        })
	        this.setData({
	          isLoading: false
	        })
	      }
    })

二、瀑布流+下拉刷新+触底加载

目标实现效果如下:

 下面是talk.js文件

// pages/talk/talk.js
// import { post } from '../../api/api'
import { getTalkList } from '../../api/user'
let app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // talkList: [],
    leftList: [],
    rightList: [],
    leftHeight: 0,
    rightHeight: 0,
    // 判断当前页是否加载完成
    finishFlag: false,
    // 请求页码
    pageNum: 1,
    // 每页个数
    pageSize: 10,
    // 判断是否已经加载完了
    isEnd: false,
    // 触底加载的loading效果
    isPageEnd: false,
    isLoading: true
  },

  // 处理数据---瀑布流
  initImg(list) {
    this.data.finishFlag = false
    if (list.length == 0) {
      // 当前页加载完成
      this.data.finishFlag = true
      return
    }
    let first = list.shift()
    wx.getImageInfo({
      src: first.coverImgUrl,
      success: (res) => {
        if (this.data.leftHeight <= this.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值