1.两个普通页面之间的跳转用uni.navgateTo(),url可携带参数。
2.普通页面跳tabbar配置过的页面需要uni.switchTab(),url不能传值。
3.uni.reLaunch()万金油跳转,可以跳转任何页面(克服了普通页面跳tabbar配置的页面url不能传值的问题。)
4.突出中间按钮的midButton,是偶数才能显示,但只支持真机环境,浏览器是没有效果的。
6.页面生命周期(考虑的是页面刷新带来的影响):
onLoad、onShow、onReady
应用生命周期,指app.vue里面的这三个
onLaunch: function() {
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
7.箭头函数没有this指向(慎用),如果在控制台打印this是undefined的,证明是箭头函数在作怪,在特殊场合别贪方便,有时候会遇到抓破头皮也找不到问题所在,就是箭头函数搞的鬼。
8.uni.request({,success:function(res){})})请求成功返回的数据直接使用this直接赋值是不生效的,因为这是一个异步函数,需要借助一个指向:let that = this
data() {
return {
WeatherGroup:{}
}
},
.....省略部分代码
methods: {
myFn:function() {
let that = this
let URL = `https://devapi.qweather.com/v7/weather/now?......`
uni.request({
url:URL,
method:'GET',
success:function(res) {
//异步不能用return
let temp = res
that.WeatherGroup = temp
}
})
}
}
9.setStorageSync 数据缓存是用来2个页面交互的,传数据传值,写在onLoad里面。
10.uni-app的<view>标签等于div标签,独占一行。
笔记
for(let i=0;i<e.length;i++){
console.log(e[i])
}
等价于 for(let item of e) {
console.log(item)
}
等价于
e.forEach((res) => {
console.log(res)
})
5.和风天气官网提供的API是免费的,每人一天1000次数,够练手了。