美文网首页慕课网实战学习笔记微信小程序开发
纯正商业级应用-微信小程序开发实战 问题

纯正商业级应用-微信小程序开发实战 问题

作者: wxy1 | 来源:发表于2018-12-18 11:10 被阅读0次

1.音乐播放器模块问题:

相邻的两个资源都是音乐资源的时候,使用wx:if无法再次触发声明周期函数
wxml

<v-music wx:if="{{classic.type == 200}}" 
                img="{{classic.image}}"
                content="{{classic.content}}"
                title="{{classic.title}}"
                src="{{classic.url}}" />

index.js

  attached: function() {
    this._recoverPlaying()
    this._monitorSwitch()
  },

改写方法依然使用hidden,同时使用observer监听属性值得改变

<v-music hidden="{{classic.type != 200}}" 
                img="{{classic.image}}"
                content="{{classic.content}}"
                title="{{classic.title}}"
                src="{{classic.url}}" />

index.js

  properties: {
    src: {
      type: String,
      observer: function(newData, oldData) {
        this._recoverStatus()
        this._monitorSwitch()
      }
    },
    title: {
      type: String
    }
  },

2._recoverStatus判断逻辑简化:

仅需要保证:音乐没有暂停且src与当前src相同时 playing为true

    _recoverStatus: function() {
      if (!mMgr.paused && (mMgr.src == this.data.src)) {
        //音乐没有暂停 播放的是当前页面的音乐
        this.setData({
          playing: true,
          rotation: 'rotation'
        })
      } else {
        this.setData({
          playing: false,
          rotation: ''
        })
      }
    },

相关文章

网友评论

    本文标题:纯正商业级应用-微信小程序开发实战 问题

    本文链接:https://www.haomeiwen.com/subject/mypkkqtx.html