小程序初始化服务器数据,微信小程序 项目实战(一)生命周期 配置服务器信息 splash启动页...

步骤一:小程序 生命周期

//app.js

App({

onLaunch: function () {

//当小程序初始化完成时,会触发onLaunch(全局只触发一次)

},

onShow: function () {

//当小程序启动,或从后台进入前台显示,会触发onShow

},

onHide: function () {

//当小程序从前台进入后台,会触发onHide

},

onError: function (msg) {

//当小程序发生脚本错误,或者api调用失败时,会触发onError并带上错误信息

},

other: function () {

//全局函数,可以被项目上的其他js文件调用

},

globalData: {

//全局对象

},

})

步骤二:配置服务器信息

903d07b85da683ab69beccf860a05a18.png

步骤三:项目结构

4fdf7f4ca6cf2f673903cd1f3384793f.png

1.数据(逻辑)

splash.js

// pages/splash/splash.js

Page({

/**

* 页面的初始数据

*/

data: {

movies: []

},

/**

* 生命周期函数--监听页面加载

*/

onLoad: function (options) {

const _this = this;

// 请求数据

wx.request({

url: 'https://api.douban.com/v2/movie/coming_soon',

data: {},

header: {

'content-type': 'json' // 默认值

},

success: function(res){

const data = res.data.subjects.slice(0,3);

// console.log(data);

_this.setData({

movies: data

})

}

})

},

// 事件绑定函数

start: function(){

// 重定向

wx.redirectTo({

url: '../board/board'

})

}

})

2.页面

splash.wxml

立即体验

3.样式

splash.wxss

/* pages/splash/splash.wxss */

page {

100%;

height: 100%;

}

swiper {

flex: 1;

height: 100%;

}

swiper-item {

flex: 1;

}

swiper-item image {

position: absolute;

height: 100%;

100%;

opacity: .8;

}

/*立即体验按钮*/

.btn {

position: absolute;

bottom: 150rpx;

left: 50%;

300rpx;

margin-left: -150rpx;

background-color: rgba(53, 73, 94, 0.7);

color: #fff;

border: 5rpx solid #fff;

font-size: 40rpx;

cursor: pointer;

}

步骤四:设置启动页

515bf3b6df7ed188c48446e0b52be53d.png

步骤五:效果图

98d60bd2edb479d8b7746df2f7863299.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值