小程序样式问题

小程序切换下一个文章或者页面,淡入淡出效果

js 复制代码
// detail.js
getArticleData: function(articleId) {
  // 开始淡出效果
  this.animate('.detail-page', [
    { opacity: 1.0, ease: 'ease-out' },
    { opacity: 0.0, ease: 'ease-out' }
  ], 500, () => {
    // 在淡出动画完成后请求文章数据
    wx.request({
      url: `${apiBaseUrl}/articles/${articleId}`,
      method: 'GET',
      success: (res) => {
        if (res.data.status === 0) {
          const data = res.data.data;
          const articleData = data.current_article;

          // 更新文章数据
          this.setData({
            title: articleData.title,
            htmlContent: articleData.content,
            nextArticleId: data.next_article_id,
            previousArticleId: data.previous_article_id,
          });

          // 开始淡入效果
          this.animate('.detail-page', [
            { opacity: 0.0, ease: 'ease-in' },
            { opacity: 1.0, ease: 'ease-in' }
          ], 500);
        } else {
          // 错误处理
          console.error('获取文章数据失败:', res.data.message);
        }
      },
      fail: (err) => {
        console.error('请求文章数据失败:', err);
      }
    });
  });
}

小程序滚动加载上一页或者下一页,滚动条不回顶部的问题

尝试了各种方案效果不是很理想,最终直接采用跳转的方案

js 复制代码
wx.redirectTo({
        url: '/pages/index/detail?id=' + this.data.previousArticleId
      });

图片高度不能自适应宽度的问题

wxml 复制代码
<image class="card-image" src="{{item.cover_image}}" mode="aspectFill"></image>
<image class="card-image" src="{{item.cover_image}}" mode="widthFix"></image>

主要问题在于mode,这里有多种模式,aspectFill这种就是显示中间一块

widthFix则是自适应宽高

头像获取问题

现在头像已经不支持点击获取了,也就说下面两种方式都失效了

js 复制代码
  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
  getUserInfo(e) {
    // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
    console.log(e)
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }

现在采用的方式为用户设置的方式。具体文档见:微信文档

相关代码

js 复制代码
<button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
  <image class="avatar" src="{{avatarUrl}}"></image>
</button> 
<input type="nickname" class="weui-input" placeholder="请输入昵称"/>

const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
  data: {
    avatarUrl: defaultAvatarUrl,
  },
  onChooseAvatar(e) {
    const { avatarUrl } = e.detail 
    this.setData({
      avatarUrl,
    })
  }
})
相关推荐
一匹电信狗2 小时前
【Linux我做主】进程优先级
linux·运维·服务器·c++·ubuntu·小程序·unix
壹立科技11 小时前
Java源码构建智能名片小程序
java·开发语言·小程序
shadouqi14 小时前
问题1:uniapp在pages样式穿刺没有问题,在components组件中样式穿刺小程序不起效果
小程序·uni-app
2501_915909061 天前
iOS电池寿命与App能耗监测实战 构建完整性能监控系统
android·ios·小程序·https·uni-app·iphone·webview
一只开心鸭!1 天前
原生微信小程序实现语音转文字搜索---同声传译
微信小程序·小程序
weixin_lynhgworld1 天前
旧物回收小程序:科技赋能,让旧物回收焕发生机
科技·小程序
此心光明事上练1 天前
微信小程序组件发布为 npm 包的具体步骤
微信小程序·小程序·npm
Byte_Me2 天前
从东南亚出发:小程序容器技术如何助力 App 快速打入全球市场?
小程序
小白_ysf2 天前
uniapp开发微信小程序(新旧版本对比:授权手机号登录、授权头像和昵称)
微信小程序·小程序·uni-app
hongkid2 天前
微信小程序私密消息
微信小程序·小程序