小程序问题

#1.wx.navigateTo跳转不了

首先 控制台报 Invoke event ToIndex in page: pages/login/login 页面无法跳转

解决的方法:

1.app.json文件中注册检查

2. 跳转的url地址和目录层级

3.跳转到的页面是非tabBar的页面吗?如果是tabBar页面,那么wx.navigateTo/wx.redirectTo只能用在非tabBar页面的跳转,要跳转到tabBar页面,需要使用wx.switchTab

#2.setTimeout里的this

解决方法:在函数中加入var that = this;

that.setData({...});

1、如果函数作为对象的方法调用,this指向的是这个上级对象,即调用方法的对象。
2、如果是构造函数中的this,则this指向新创建的对象本身。

#3.小程序里不需要jsonp格式的数据,返回json就好

#4.外部js引用

1.我们先建立一个common.js文件,在common.js编写我们的程序,

function myfunc() {
console.log("myfunc....");
}

module.exports.myfunc = myfunc; 这样暴露接口,这里不暴露是不能引用的,

2.在文件域js内

var common = require("../../common.js");去链接过来,光链接过来还不行!

var app;
var common = require("../../common.js");
Page({
data:{

},
onLoad:function() {
app = getApp();
this.setData({version:app.globalData.appName});
common.myfunc();  //最后我们需要执行才能生效!
}
})

#5.小程序是如何实现跨域的?

后端映射、你请求的接口实际到微信的后端做了一道映射

微信后端拿到你的wx.request调用的url、用后端请求后端

拿到数据后将body返给你

这就是为什么、请求后端之后、拿回来的只有body没有header、取不到response header

以前fetch也是可以在开发者工具用的、后面被屏蔽了

#6.json字符串对象互转

1.字符串转化为 对象

newObject=JSON.parse(options.infoStr)

2.对象转化为字符串

infoStr=JSON.stringify(object)

#7.bindtap和catchtap

bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒泡事件向上冒泡

#8.swiper

<view class='content'>
  <swiper vertical='true' indicator-dots="true" autoplay="true"> //纵向滚动
    <swiper-item><image src='/pages/images/111.png'></image></swiper-item>
    <swiper-item><image src='/pages/images/222.png'></image></swiper-item>
    <swiper-item><image src='/pages/images/333.png'></image></swiper-item>
    <swiper-item><image src='/pages/images/444.jpg'></image></swiper-item>
  </swiper>
</view>

猜你喜欢

转载自blog.csdn.net/G_wendy/article/details/80828520