优势:
onLoad() {
console.log('页面加载')
},
onShow() {
console.log('页面显示')
},
onReady() {
console.log('页面初次渲染完成')
},
onHide() {
console.log('页面隐藏')
},
onUnload() {
console.log('页面关闭')
},
onShareAppMessage() {
console.log('页面分享')
},
onPageScroll() {
console.log('页面滚动')
},
onBackPress() { // 不支持小程序,通常写在onLoad中
console.log('页面返回')
},
"tabBar":{
"color":"#8F8F94",
"selectedColor":"#007AFF",
"backgroundColor":"#FFFFFF",
"borderStyle":"black",
"list":[
{
"pagePath":"pages/index/index",
"text":"首页",
"iconPath":"static/tabBar/index1.png",
"selectedIconPath":"static/tabBar/index2.png"
},
{
"pagePath":"pages/me/me",
"text":"我的",
"iconPath":"static/tabBar/mine1.png",
"selectedIconPath":"static/tabBar/mine2.png"
},
{
"pagePath":"pages/search/search",
"text":"搜索",
"iconPath":"static/tabBar/search1.png",
"selectedIconPath":"static/tabBar/search2.png"
}
]
}
<view class="page">
<swiper
:indicator-dots="true"
:autoplay="true"
class="carousel">
<swiper-item>
<image src="../../static/swiper/swiper_1.jpg" class="carousel">image>
swiper-item>
<swiper-item>
<image src="../../static/swiper/swiper_2.jpg" class="carousel">image>
swiper-item>
swiper>
view>
ps:小程序中的状态栏禁不掉
在pages.json中的style属性添加禁用:
"style": {
"app-plus": {
"titleNView":false //禁用
}
}
方法一
在commons/commons.js中提取全局变量:
//提取公共文件
const doubanUrl ="https://images.weserv.nl"; //豆瓣电影
export default { doubanUrl } //常量导出
import common from "../../commons/commons.js"
//拼接使用"image":common.doubanUrl+"/?url=img1.doubanio.com/view/photo/l/public/p2410755737.webp",
方法二
也可以在main.js中挂载到Vue:
Vue.prototype.doubanUrl="https://images.weserv.nl";
所有页面都可以获取Vue对象(this.即可,无需import):
"image":this.doubanUrl+"/?url=//img3.doubanio.com/view/photo/l/public/p2556561071.webp",
需要登录之后对域名进行配置,并且只支持Https协议。
一旦允许某些域名之后,就可以不用勾选“不校验合法域名、HTTPs证书”。
// 获取热门数据
getHotData(){
// 特别注意:非H5端不能用uni.request来请求本地json数据!!!
const dataRes = await this.$http({url:'/new_movies.json'})
const { subjects : dataRes } = require('../../static/mock/top250.json')
// 截取10条数据
let newArr=[]
for(let i=0;i<dataRes.length;i++){
if(i+this.hotCount-10<this.hotCount){
let item=dataRes[i+this.hotCount-10]
// 对图片做处理.
item.images.small=item.images.small.replace('https://','https://images.weserv.nl/?url=')
newArr.push(item)
}
}
this.hotData=[...this.hotData,...newArr]
},
<scroll-view scroll-x="true" class="page-block hot">
<view class="single-poster" v-for="item in hotData" :key="item.id">
<view class="poster-wapper">
<image :src="item.images.small" class="poster">
image>
<view class="movie-name">{{item.title}}view>
<view class="movie-score-wapper">
<view class="movie-score">9.0view>
view>
view>
view>
scroll-view>
<view class="hot-movies page-block">
<video
v-for="hotTrailer in hotTrailerList"
:src="hotTrailer.src"
:poster="hotTrailer.poster"
class="hot-movie-single" controls>
video>
view>
配置相应的CSS样式:
/* 热门预告 */
.hot-movies{
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between; //视频间隙
padding: 0 20upx 20upx 20upx;
}
.hot-movie-single{
width: 350upx;
height: 220upx;
margin-top: 10upx;
}