本人一手独立开发小程序----附代码
导入我们的图片
最后。我们看一下效果
是不是美美哒?
看一下代码
<view class="index">
<scroll-view scroll-y="true" style="height:{{hg}}px;" bind:scrolltolower="scrolltolower">
<view style="width: 100%;">
<view class="container">
<view style=" display: inline-block;" wx:for="{{a.data}}">
<view style="width: {{w}}px;">
<image src="{{item.en}}" mode="widthFix" style="width: {{w}}px;height: 200rpx;border-radius: 15rpx;position: relative;">
<view style="position: absolute;bottom: 3%;left: 3%;font-size: 30rpx;color: rgb(226, 226, 226);width: 200rpx;height: 40rpx;background: rgb(240, 228, 228);border-radius: 30rpx;opacity: 0.5;display: flex;align-items: center;justify-content: center;">
</view>
<view style="position: absolute;bottom: 3%;left: 3%;font-size: 30rpx;color: rgb(255, 255, 255);width: 200rpx;height: 40rpx;border-radius: 30rpx;display: flex;align-items: center;overflow: hidden;font-size: 22rpx;font-weight: bold;">
<image src="https://img.zcool.cn/community/01ccaf58c65411a801219c77b0a16c.png@1280w_1l_2o_100sh.png" style="width: 40rpx;height: 40rpx;border-radius: 50%;"></image>
{{item.zh}}
</view>
</image>
</view>
</view>
</view>
</view>
</scroll-view>
</view>
// index.js
// 获取应用实例
const app = getApp()
Page({
data: {
okl:"",
hg:"",
list: [
{"url":"https://vkceyugu.cdn.bspapp.com/VKCEYUGU-4c2d237a-afe3-4d95-94cf-e0d8f6b312f0/9f66b2f5-4025-45ab-8214-3ef9538bc756.png"},
{"url":"https://vkceyugu.cdn.bspapp.com/VKCEYUGU-4c2d237a-afe3-4d95-94cf-e0d8f6b312f0/9f66b2f5-4025-45ab-8214-3ef9538bc756.png"},
{"url":"https://vkceyugu.cdn.bspapp.com/VKCEYUGU-4c2d237a-afe3-4d95-94cf-e0d8f6b312f0/7281c9a3-10cb-4ca3-a203-6db193476cfe.png"},
],
w:"",
okna:"",
w1:"",
ks:'0',
js:"10",
a:"",
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs'
})
},
keysearch(res){
console.log(res)
this.setData({
okna:res.detail.value
})
},
tj(res){
wx.navigateTo({
url: '/pages/search/search?name='+this.data.okna,
})
},
zt(res){
console.log(res.currentTarget.dataset.id)
wx.navigateTo({
url: '/pages/pge/pge?id='+res.currentTarget.dataset.id,
})
},
scrolltolower(){
let a=this;
a.setData({
ks:Number(a.data.js)+Number(1),
js:Number(a.data.js)+Number(10),
})
wx.request({
url: 'https://api.phpcos.cn/aihh.php',
data:{
mc:'香蕉',
ks:a.data.ks,
js:a.data.js,
},
success(res){
console.log(res)
a.setData({
a:[...a.data.a,...res.data]
})
}
})
},
onLoad() {
console.log(123)
var data= wx.getWindowInfo()
console.log(data.safeArea.width)
console.log(data.safeArea.height)
let a=this;
a.setData({
hg:data.safeArea.height,
// w:Number(data.safeArea.width)/2,
w:Number(Number(data.safeArea.width)/2)-(18)
})
wx.request({
url: '/aihh.php',
data:{
mc:'香蕉',
ks:a.data.ks,
js:a.data.js
},
success(res){
console.log(res)
a.setData({
a:res.data
})
}
})
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
zc(res){
console.log(res)
wx.navigateTo({
url: '/pages/zcwc/zcwc?lx='+res.currentTarget.dataset.lx,
})
},
getUserProfile(e) {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
onShow: function () {
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: 1
})
}
},
getUserInfo(e) {
// 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
console.log(e)
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})