当前位置:网站首页>For instruction, uploading pictures and display effect optimization of simple wechat applet development
For instruction, uploading pictures and display effect optimization of simple wechat applet development
2022-07-03 03:34:00 【Water W】
This is a continuation of the previous one Simple version of Page Jump of wechat applet development 、 Data binding 、 Get user information 、 Get user location information
https://blog.csdn.net/qq_45956730/article/details/125252305?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22125252305%22%2C%22source%22%3A%22qq_45956730%22%7D&ctrtid=UdFQC
Catalog
6、 ... and 、 To upload pictures
Display effect optimization 1:
Display effect optimization 2:
5、 ... and 、for Instructions
To write goods page
(1)wxml
The interior is equivalent to helping us make a “for item in dataList” loop
<!--pages/goods/goods.wxml-->
<text> List of goods </text>
<view>
<view wx:for="{
{ dataList }}">{
{index}}-{
{item}}</view>
</view>
<view>
<view wx:for="{
{ UserInfo }}">{
{index}}-{
{item}}</view>
</view>
or
<!--pages/goods/goods.wxml-->
<text> List of goods </text>
<view>
<view wx:for="{
{ dataList }}" wx:for-index="idx" wx:for-item="x">{
{idx}}-{
{x}}</view>
</view>
<view>
<view wx:for="{
{ UserInfo }}" wx:for-index="idx" wx:for-item="x">{
{idx}}-{
{x}}</view>
</view>(2)js
// pages/goods/goods.js
Page({
/**
* Initial data of the page
*/
data: {
dataList: [" Input "," Buddha's birthday "," Birthday song "],
UserInfo: {
name:"alex",
age: 18,
gender: false
}
},
/**
* Life cycle function -- Monitor page loading
*/
onLoad(options) {
},
/**
* Life cycle function -- Listening page first rendering completed
*/
onReady() {
},
/**
* Life cycle function -- Monitor page display
*/
onShow() {
},
/**
* Life cycle function -- Monitor page hidden
*/
onHide() {
},
/**
* Life cycle function -- Monitor page uninstall
*/
onUnload() {
},
/**
* Page related event handler -- Monitor user pull-down action
*/
onPullDownRefresh() {
},
/**
* Handling function of page pull bottom event
*/
onReachBottom() {
},
/**
* Users click the upper right corner to share
*/
onShareAppMessage() {
}
})Show the effect :

6、 ... and 、 To upload pictures
To write home page :
(1)wxml
<!--pages/home/home.wxml-->
<view class="menu">
<view class="item">
<image src="/static/link-01.png"></image>
<text> The high-quality goods </text>
</view>
<view class="item">
<image src="/static/link-01.png"></image>
<text> The high-quality goods </text>
</view>
<view class="item">
<image src="/static/link-01.png"></image>
<text> The high-quality goods </text>
</view>
<view class="item">
<image src="/static/link-01.png"></image>
<text> The high-quality goods </text>
</view>
</view>
<navigator url="/pages/list/list?id=566"> Jump to the page </navigator>
<view bindtap="uploadImage"> Please upload the picture :</view>
<view class="images">
<image wx:for="{
{images}}" src="{
{item}}"></image>
</view>(2)js
// pages/home/home.js
Page({
/**
* Initial data of the page
*/
data: {
images: ["/images/link-01.png","/images/link-02.png","/images/ Default Avatar .jpeg"]
},
uploadImage() {
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success:function(res) {
console.log(res)
}
})
},
/**
* Life cycle function -- Monitor page loading
*/
onLoad(options) {
},
/**
* Life cycle function -- Listening page first rendering completed
*/
onReady() {
},
/**
* Life cycle function -- Monitor page display
*/
onShow() {
},
/**
* Life cycle function -- Monitor page hidden
*/
onHide() {
},
/**
* Life cycle function -- Monitor page uninstall
*/
onUnload() {
},
/**
* Page related event handler -- Monitor user pull-down action
*/
onPullDownRefresh() {
},
/**
* Handling function of page pull bottom event
*/
onReachBottom() {
},
/**
* Users click the upper right corner to share
*/
onShareAppMessage() {
}
})(3)wxss
/* pages/home/home.wxss */
image {
width: 100rpx;
height: 100rpx;
border-radius: 50rpx;
}
.menu {
display: flex;
/* Arrange horizontally , Specify the spindle direction */
flex-direction: row;
/* How elements are displayed horizontally , Specify how to display in the spindle direction :center */
justify-content: space-around;
}
.menu .item {
display: flex;
flex-direction: column;
align-items: center;
}
.images {
width: 200rpx;
height: 200rpx;
padding: 5rpx;
}
Show the effect :
(1) Click on “ Please choose a picture ” after , A selection page will pop up ,

(2) On the pop-up selection page , After selecting the picture ,console The selected picture information will be printed in .

Display effect optimization 1:
(3) here , We modify uploadImage() function , In order to upload and display the pictures we choose on the page ,
data: {
images: ["/images/link-01.png","/images/link-02.png","/images/ Default Avatar .jpeg"]
},
uploadImage() {
var that = this
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success:function(res) {
console.log(res)
that.setData({images: res.tempFilePaths})
}
})
},(4) recompile , Click on “ Please choose a picture ” after , Select a picture on the pop-up selection page ,

Click on “ open ” after , The display effect of the page is ,

Display effect optimization 2:
(3) here , We modify uploadImage() function , In order to make the pictures we choose can be uploaded and displayed on the page existing After the picture of ,
data: {
images: ["/images/link-01.png","/images/link-02.png","/images/ Default Avatar .jpeg"]
},
uploadImage() {
var that = this
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success:function(res) {
console.log(res)
// Set up images, The picture on the page is automatically modified
// that.setData({images: res.tempFilePaths})
// The default image + Selected pictures
that.setData({images: that.data.images.concat(res.tempFilePaths)})
}
})
},
/**
* Life cycle function -- Monitor page loading
*/
onLoad(options) {
},(4) recompile , Click on “ Please choose a picture ” after , Select a picture on the pop-up selection page ,

Click on “ open ” after , The display effect of the page is ,

边栏推荐
- Introduction à mongodb
- Don't use the new Dede collection without the updated Dede plug-in
- 小程序获取用户头像和昵称
- QQ小程序开发之 一些前期准备:预约开发账号、下载安装开发者工具、创建qq小程序
- docker安装及启动mysql服务
- [Chongqing Guangdong education] cultural and natural heritage reference materials of China University of Geosciences (Wuhan)
- Applet (continuous update)
- PAT乙级“1104 天长地久”DFS优化思路
- Use three JS make a simple 3D scene
- navicat 导出数据库的表结构
猜你喜欢
![Mongodb replication set [master-slave replication]](/img/2c/8030548455f45fa252062dd90e7b8b.png)
Mongodb replication set [master-slave replication]

小程序获取用户头像和昵称

Hi3536c v100r001c02spc040 cross compiler installation

Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11

umi 路由拦截(简单粗暴)

Idea format code idea set shortcut key format code

Latest version of NPM: the "NPM" item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check

Application of derivative in daily question

Pytoch configuration

The series of hyperbolic function in daily problem
随机推荐
Tidal characteristics of the Bohai Sea and the Yellow Sea
MongoDB安装 & 部署
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 03 operators and expressions
Idea set method call ignore case
简易版 微信小程序开发之for指令、上传图片及展示效果优化
递归使用和多维数组对象变一维数组对象
Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
FileZilla client download and installation
Compare float with 0
Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
解决高并发下System.currentTimeMillis卡顿
PHP generates PDF tcpdf
@Accessors注解作用指定前缀遵守驼峰命名
leetcode:动态规划模板
Pytorch multi card distributed training distributeddataparallel usage
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
The file marked by labelme is converted to yolov5 format
Unity3d RPG implementation (medium)
C语言HashTable/HashSet库汇总
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf