系列文章目录
学习篇第一篇我们讲了编译器下载,项目、环境建立、文件说明与简单操作:第一篇链接
第二、三篇分析了几个重要的配置json文件,是用于对小程序进行的切换页面、改变图标、控制是否能被搜索到等的操作第二篇链接、第三篇链接
第四五篇学习了框架、api组件:
第四篇链接:rpx和轮播图
第五章链接:文字组件和跳转组件
本篇会将组件讲完,并进入事件绑定的学习。
文章目录
- 系列文章目录
- 一、scroll-view组件图片滚动
- [二、background image背景图片](#二、background image背景图片)
- 三、事件绑定
一、scroll-view组件图片滚动
1.滚动代码
html
<scroll-view class="scroll-x" scroll-x>
<view>1</view>
<view>2</view>
<view>3</view>
</scroll-view>
css
.scroll-x{
width: 100%;
white-space: nowrap;
background-color: yellowgreen;
view{
display: inline-block;
width: 300rpx;
height: 80rpx;
&:last-child{
background-color: red;
}
&:first-child{
background-color: blue;
}
}
}
可以实现横向拖动。scroll-x是横向移动,scroll-y是纵向移动。
二、background image背景图片
注意,背景图片不支持本地图片,只能由网络图片。
1)框架
html
<view class="bg_test">a</view>
2)scss
代码如下(示例):
c
.bg_test{
height: 400rpx;
background-image: url(data:image/gif;base64,R0lGODlh2ADJAHAAACH5BAEAAJgALAAAAADYAMkAh2yQqmxs/2yQ/wAkqgAAAAAAVUhs/yRIVZCQqiQkVQAkAGxsqrS0/5C0/7TY/9j8/9jY/5CQ//z8/7S0qrTYqpC0qkhsqvz8qtjYqrRsVWwkVUgAAEgkVSRIqpAkAGwAVZAAAEhIVWwAAEhIqmwkAEgAVUhsVSQkqmxsVQAkVZCQVdi0qiRsAABIACRIAJDYVbT8VbTYVdj8VZDYAGzYACS0ACTYALT8AJD8AEi0AAC0AEjYACRsVSRI/0j8ANj8AGz8AJD8VWz8VUhsAEjYVQDYACTYVWzYVQC0VWy0VSS0VUi0VWxsAGy0AJC0AACQAEiQAABsACSQACQkAGyQVZC0VWyQAEiQVQDYVUj8VbS0VZBs/7SQqiSQVbRIALQkALRIVbRsqtiQAPyQVUhIAABsVdhIAPxIVfxIALSQANiQ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Y1eeN3mSk3sIrtevVgOzd3j7o3kkC33Yb37kyX+lNX+vFXmp83/j93vCt3zG5X/St3mB7A/Z1X+713vkV33IjX4waYGrMXwNGYP5VYPkFYAeWu0CAXumNRUPY/1jKmzL3ywA01LZ+IwERm7K4CoEALU83eAM4iN6NMqbl8oIWnklIKGGEVbkUrj/km14XJjIYluGGrGERnkmSNOGNZSgVpqQgfs4XjuEZnjJ8veERVmIeRmEnZmEhLqkpNmIrxuE10OEl7mEVBuIWjuIhBmMaFmMszoBdbD+TConBArX6015D0rsNGC8vqANJqyicWzpJwLSS1AIOkDSL4LkYixA8jgM9Dr8+/mNkXAFB3gNCxjVDRmQ6XuQ7bsJHNqlIRqhJDmSvu+RCnsBNVmQ7buRPhmTFkmRArmRTxuScPORErmNGBgNHfmU+HmVZtuRa1mRc7uSVVYMmjEUusM09SdiAXwwsZg6mzxI/SWip9Qtc0VO/9YMD4oPmGVrmDejDZ96AaDa9wG0p0xtnbM4tbebmcfZmcXZmEoDmFZBmc96D9RtnNMxm0Wvnv1JmeCYkeR5nei5nar7naSayfd5mgfbnbw5nhiboaT7n9WNmOFDofn5ngX5oZp6EyIvFvCEAvwFpAriEkS7pkRbpmyiAj86bS0jpm3jpmzjplh7pkB5plpbpmI5pkjbpmo5pnCZpna7pmZZpn77poRbqngZpoobpozbppM6bjw4IADs=);
}
以上是使用了base64编码,这样可以有效的解决我们没有网络地址图片的困境。本地图片转base64格式工具
如果你由自己的网页、服务器,你可以上传图片到自己的网页,然后用网络图片地址。下面给吃一个例子
http://8.131.91.46:6677/bgimage.png
你可以将background换成
css
background-image: url(http://8.131.91.46:6677/bgimage.png);
可以实现背景图片。
三、事件绑定
1)绑定方法
先在框架文件wxml中添加botton绑定,有以下两种方式:
html
<view bind:tap="fnName"></view>
html
<view bindtap="fnName"></view>
例子:<button type="primary" size="mini" bind:tap="tap_test">绑定事件</button>
2)处理函数
在js中需要调用小程序提供的Page方法来注册小程序的页面,我们可以在js文件的page方法中创建事件处理函数。
css
tap_test(){
console.log('tap触发')
},
3)返回函数实例
一个现实的问题:如果我们需要在点击按钮的时候获得文本框中的内容,怎么办 ?
a)文本框教学
由于文本框默认没有边框,我们先去app.scss中加入边框设置。
css
input{
border: 1px solid black;
}
然后去xwml框架中加入input输入框
html
<input type="text" />
就显示出来啦~
再说说文本框的事件绑定
html
<input type="text" bind:input="input_convey_test" />
以上代码在wxml中
css
input_convey_test(event){
//为了获取值,我们需要引入event
console.log(event.detail.value)
},
以上代码在.js文件中
console.log就是在console框中输出。
效果如下
b)冒泡事件和非冒泡事件
冒泡事件:子组件被触发,会触发父组件
非冒泡事件:子组件被触发,不会触发父组件
当我们这么写绑定的时候:<input type="text" catch:input="input_convey_test" />
就不会触发父组件。
注意,默认为 冒泡事件。
currentTarget可以调取事件绑定者,target对应事件触发者
c)问题实现
xwml:
html
<view class="search-top">
<input bind:input="inputCom" value="{{inputValue}}"></input>
<text bindtap="doSearch">搜索</text>
</view>
js:
c
Page({
data: {
// 存储输入框的值
inputValue: ''
},
// input输入框的bindinput事件
inputCom(e){
this.setData({
inputValue: e.detail.value
})
console.log(this.data.inputValue);
},
doSearch(){
// 这里就可以使用输入框输入的值啦,通常我们在这里发起ajax请求会用到
console.log('search:',this.data.inputValue);
}
})