微信小程序填坑之路

1 为何设置tabBar以后。底部tabBar无法显示??

多半原因:在app.json配置文件中把index放在了最前面。
page({
"pages":[
"pages/logs/logs",
"pages/index/index", //调整位置
"pages/test/test",
"pages/temps/temps"
],
})

2 如何实现长按复制文本,在另一个页面粘贴文本?(a页面复制,b页面粘贴)
a.xwml页面
<textselectable="true"bindlongtap="copytext"> //注意长按事件
{{msg}}
</text>

a.xws(js文件)
page({
data: {
msg:"mseoffjwiejfijweif我是用来测试复制粘贴的文本g"
},
copytext:function(e){
var that=this;
wx.setClipboardData({
data: that.data.msg,
success:function(res){
console.log(res) // data
}
})
}
})
b.xwml页面
<view>{{posterMsg}}</view>
<inputclass="put"placeholder="粘贴文本"vaule="{{val}}"auto-focus bindlongtap='poster'/>
b.xws(js文件)
Page({

/**
* 页面的初始数据
*/
data: {
val:""
},
poster:function(){
var _this=this;
wx.getClipboardData({
success:function(res){
_this.setData({
val:res.data
})
}
})

},
})

3 在app.js文件中根据后端返回值做页面跳转的时候。为什么会报路径错误?
总是报错pages/index/pages/signLogin/siginLogin is not in app.js

if(res.data.status==0){
wx.navigatorTo({
   url:"page/regist/regist"    //注意,如果直接写绝对路径是错误的,
正确写法是
 // url:"../regist/regist"     (依然有疑惑)
})
}

4小程序页面之间跳转的时候。如果要带上多个参数该如何传递?
解决办法:通过&符号进行分割传值
var id = e.currentTarget.dataset.id;
var typeval = e.currentTarget.dataset.type;
var boxId=this.data.bid;
var name="sena"
wx.navigateTo({
url: '../movieCont/movieCont?id=' +id+'&bid=' + boxId+"&name="+name,
})

5小程序页面传值如果带有?等特殊符号。在新页面中无法得到这些特殊符号后面的值?
解决办法:通过encodeURIComponent,该 函数会保留特殊符号后的值。
a.wxml页面:
var url="https://www.cede.com?id=213"
wx.navigateTo({
url: '../movieCont/movieCont?id=' +id+'&url'=url,
})
b页面接受:
page({

onload:function(options){
var url=options.url;
===>此时url="https://www.cede.com";id值无法得到。被截取
}

})
解决办法:
wx.navigateTo({
url: '../movieCont/movieCont?id=' +encodeURIComponent(id+'&bid=' + boxId),
})
小程序中当删掉某个内容。如何做到当前页面同步跟新界面?
解决办法:
删除结束以后,要在onshow事件中再去向服务器发一次获取内容的请求。这样就能在当前页面中同步看到被删除的元素被删掉了。
6 web-view组件在模拟器上渲染内容正常,真机上无法显示。也不报错,调试器也不见了?
原因:
1  基础库 1.6.4 开始支持,微信版本要升级到至少6.5.16
2 参数编码和解码的原因。
实例:
  a页面中获取到网址。该网址后面带有一个文章id,指向具体的某篇文章。
wx.navigateTo({
url: "../queryArtic/queryArtic?id="+id+"&url="+encodeURIComponent(articleAdress)
})
具体的是形如:https://www.rujian.vip/article/showarticle.html?id=354
b 页面中通过在onload(options)的options去接收a页面传过来的值。
var id = options.id;
var urlAddress =decodeURIComponent(options.url);
这里特别要注意:(1),如果带有参数:如上例中的?id=xx&url=xxx,如果没有通过encodeURIComponent编码。在b页面中是接受不到?后面的值的。
只能获取到到https://www.rujian.vip/article/showarticle.html
(2) 虽然在b页面中通过options.id能获取到该值,但是真机上是一片空白的,甚至连调试器也没有。模拟器是正常的,问题就出
在解码,必须要通过对应的decodeURIComponent(options.url)对其进行解码。
7 wx.request发送请求,method为post为何数据返回false?
原因,没有设置header选项。例子如下
var urlAddress ="/contact/update"
var targetResponseData =this.data.targetResponseData;
var data = {
sessionID: sessionID,
id: this.data.targetResponseData.id,
name: that.data.targetResponseData.name,
mobile: that.data.targetResponseData.mobile,
gender: that.data.targetResponseData.gender,
relationship: that.data.targetResponseData.relationship,
age: that.data.targetResponseData.age,
email: that.data.targetResponseData.email,
idNumber: that.data.targetResponseData.idNumber,
region: that.data.targetResponseData.region,
address: that.data.targetResponseData.address
}
this.setTarget(urlAddress, targetResponseData, data)
setTarget:function(){
wx.request({
url: utils.baseUrl + urlAddress,
header: { 'content-type': 'application/x-www-form-urlencoded' },
method:"POST",
data:data
})
}
服务器结构返回false。应该添加header选项
header: { 'content-type': 'application/x-www-form-urlencoded' },
一切正常
8:小程序中音频管理对如何获取当前音频的duration和updata时的值?
innerAudioContext的基本用法:
一:创建innerAudioContext对象
const innerAudioContext = wx.createInnerAudioContext();
二:映射音频src地址
innerAudioContext.src=""https://www.rujian.vip"+resData.resourceURL"
三:点击某个按钮,执行 innerAudioContext.play();
四:点击停止按钮,执行 innerAudioContext.pause();
问题:如何获取到音频的duration值和更新时的当前的值?
innerAudioContext.onTimeUpdate====》该事件表示音频在播放时更新时触发的动作。

单独执行innerAudioContext.play()时调用innerAudioContext.onTimeUpdate是无法获取到duration和curtime的值的。这里必须要手动的执行
innerAudioContext.onPlay(()=>{....})事件。大坑!!!
获取duration的值必须是innerAudioContext.duration,而不是其回调里的e

猜你喜欢

转载自blog.csdn.net/baidu_41601048/article/details/78997421