小程序碰到問題記錄

1.小程序想根據內容撐開平鋪放入背景圖

<view  class\="detail"  style\="background:url(XXX) repeat">

2.field 表單的字想兩端對齊

image.png

text-align: justify;
text-align-last: justify;

3.小程序支付

return  new  Promise(resolve => {

  payOrder(orderNo).then(res => {

    if (res.data.code === "SUCCESS") {

      wx.requestPayment({

        "timeStamp": res.data.timeStamp,

        "nonceStr": res.data.nonceStr,

        "package": res.data.package,

        "signType": res.data.signType,

        "paySign": res.data.paySign,

        success() {

            resolve();

        },

        fail() {

            wx.showToast({

            title: "支付失敗"

            })

        }

    })

} else {

    wx.showToast({

    title: res.data.msg,

    icon: "none"

    })

}

})

4.動態獲取元素高度

var obj=wx.createSelectorQuery();
obj.selectAll('.className').boundingClientRect(function (rect) {
    console.log(rect[0].height)
    console.log(rect[0].width)
})
obj.exec() ;

5.小程序搖一搖

// 搖一搖html

accelerometerChange() {

wx.onAccelerometerChange(res => {

// 左右搖

if(!this.data.isYao){

return

}

if (Math.abs(res.x) > 0.3 && Math.abs(res.y) > 0.3) {

// 搖一搖以後的事件例如:音樂,動畫。。。

}

})

},

記得離開的時候銷燬node

onHide() {

    this.setData({

    isYao:false

    })

},

5.建立背景音樂

const bgMusic = wx.getBackgroundAudioManager() //建立背景音樂
// 開始播放git

listenerButtonPlay: function (src) {

var that = this

bgMusic.title = src

bgMusic.src = src;

bgMusic.onTimeUpdate(() => { //監聽音頻播放進度

// console.log(bgMusic.currentTime)

})

bgMusic.onEnded(() => { //監聽音樂天然播放結束

that.listenerButtonPlay(that.data.musicMsg)

})

this.setData({

shifouplay: true,

})

bgMusic.play(); //播放音樂

},
//暫停

audioPause: function () {

var that = this

let shifouplay = this.data.shifouplay

if (shifouplay){

this.setData({

shifouplay:false,

})

bgMusic.pause(); //播放音樂

}else{

this.setData({

shifouplay: true,

})

bgMusic.play(); //暫停播放音樂

}

},
//中止播放

listenerButtonStop: function () {

bgMusic.stop()

},
離開的時候記得銷燬音樂

6.後臺給你的數據是標籤須要解析

解決方式使用wxParse
1.在github 上下載
https://github.com/icindy/wxParse
2.把wxParse文件夾複製到你的項目裏
3.在app.wxss裏引用樣式;防止樣式錯亂;也能夠局部引入,在你須要的文件.wxss 裏引入
@import "/wxParse/wxParse.wxss";
4.在須要解析html內容的頁面對應的js文件裏引入wxParsegithub

var  WxParse = require('../../wxParse/wxParse.js');

動態獲取內容小程序

let that=this;
const article = res.data.data.node //帶有html的
WxParse.wxParse('article', 'html', article, that, 5);

第三個 article 是你要渲染的數據名稱
* WxParse.wxParse(bindName , type, data, target,imagePadding)app

            * 1.bindName綁定的數據名(必填)xss

            * 2.type能夠爲html或者md(必填)ide

            * 3.data爲傳入的具體數據(必填)動畫

            * 4.target爲Page對象,通常爲this(必填)ui

            * 5.imagePadding爲當圖片自適應是左右的單一padding(默認爲0,可選)*/

注意:這裏不須要setData; 做者由於setData 找了半個小時的bug,尷尬
5.到了引用的地方了在wxml裏
最頂部

<import  src="../../wxParse/wxParse.wxml"  />

內容裏

<view  class="main">

<template  is='wxParse'  data="{{wxParseData:article.nodes}}"/>

</view>
相關文章
相關標籤/搜索