小编我将用CSDN记录软件开发之路上所学的心得与知识,有兴趣的小伙伴可以关注一下!也许一个人独行,可以走的很快,但是一群人结伴而行,才能走的更远!让我们在成长的道路上互相学习,让我们共同进步!
目录
前言
一、步骤
1、下拉框实现
2、下载阿里巴巴的icon图标以及整合到微信开发者工具中
二、下拉框实现
第一步:创建包
第二步:右击pages==》新建文件夹==》components
第三步:接下来使用以下包来进行操作
第四步:test包中的代码(创建一个组件)
test.js
test.json
test.wxml
test.wxss
第五步:select包中的代码
select.js
select.json
select.wxml
select.wxss没有写任何代码
三、下载阿里巴巴的icon图标以及整合到微信开发者工具中
1、官网下载 iconfont-阿里巴巴矢量图标库
2、搜索图标之后,悬浮,加入购物车
3、加载至项目中
4、下载以及复制css代码
1、查看css代码
2、复制页面代码进,wxss
5、如果需要上图的第四步,那么进行以下操作
1、进入转换代码的官网,将@font-face转换成Base64 编码
2、解压阿里巴巴icon的压缩包
3、添加字体
4、下载
5、将style.css替换wxss
6、将图一stylesheet.css中的@font-face替换图二的@font-face
再右击components==》新建Components
Component({
properties: {
title:{
type: String,
value: ""
},
nameList: {
type: Array,
value: [],
observer: function(){
//有的时候选项组是后端获取数据来的,初始化时可能为[],所以这里使用obersver,当父组件中值改变时触发
this.processData();
}
},
nowId: {
type: Number,
value: -1
},
nowName: {
type: String,
value: "",
observer: function(){
this.setData({select: this. properties.nowName,
selectId: this.properties.nowId,});
}
},
placeholder: {
type: String,
value: ""
}
},
/**
* 页面的初始数据
*/
data: {
selectcontent: [],
changable: false, //箭头切换
select: undefined, //选中的值
selectId: undefined, //选中的id
},
methods: {
// 下拉框收起和展开
startChange(e) {
this.setData({
changable: !this.data.changable
})
},
// 选择数据后回显
changecontent(e) {
this.setData({
select: e.currentTarget.dataset.datavalue.name,
selectId: e.currentTarget.dataset.datavalue.id,
changable: false
})
this.triggerEvent("handleChange", {selectId: this.data.selectId, select: this.data.select});//向父组件传参
},
//处理数据,复制一遍,因为子组件不能直接改变父组件的传进来的值。
processData(){
let options = [];
let that = this;
this.properties.nameList.forEach((item) => {
options.push({
id: item.id,
name: item.name,
});
}); //forEach
this.setData({
selectcontent: options,
select: that.properties.nowName,
selectId: that.properties.nowId,
});
}
}
})
{{title}}
{{select}}
{{placeholder}}
{{item.name}}
注意:小编的已经引入了icon的css(可以根据你心仪的图标来,下面会讲到操作)
.select_all_view{
display: flex;
z-index: 999;
}
.select_view{
display: inline;
}
.select_title{
margin-right: 10rpx;
}
.inputPlaceholder{
min-width: 300rpx;
height: 45rpx;
background-color: rgba(255, 255, 255, 0.5);
border: 1px solid #DEDEDE;
padding: 4rpx 0rpx 10rpx 10rpx;
color: #252525;
font-weight: 400;
border-radius: 10rpx;
position: relative;
overflow:hidden;
text-overflow: ellipsis;
white-space:nowrap;
}
.jiantou1{
position: absolute;
right: 10rpx;
top: 8rpx;
}
.content{
position: absolute;
z-index: 999;
min-width: 280rpx;
max-height:270rpx;
background: #FFFFFF;
box-shadow: 0px 0px 10px 1px rgba(88, 88, 88, 0.8);
border-radius: 0 0 5% 5%;
padding: 20rpx;
overflow-x: hidden;
overflow-y: scroll;
}
.content>.inputPlaceholder{
padding: 10rpx 0;
}
.select_view .active{
color:#46678d;
}
/* icon标签 */
@font-face {
font-family: 'iconfont';
src: url('iconfont.eot');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'iconfont';
src: url('data:font/woff2;charset=utf-8;base64,d09GMgABAAAAAAjUAA0AAAAAEHAAAAh/AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP0ZGVE0cGh4GYACDChEICpIMjW8LJgABNgIkA0IEIAWFAgeBbBtEDREVq20j+5mQzQmuWxiESjO2sCdd537T8Ug8/Lefdt/M/0naLjBZQFW3ACxJEqDrCo3CMCiWe3x+wNP+ZXM73q0aXA9Ax25usrsJndsRyf9ODkBHH6T25H0ARWCysVfr4Lx4oXTGNPrQ/66pLYOqG2WkSJi9WfVb/rlrm5tKBkCSQFWokRKTyBLR6LmqkZuUs6pLeV5SiCk8/eeffYjtv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2p/U7sSxEKtn7U2xNT/aBfKiGldqKdzE4rTCsf5Ja4jkukChmZSXKn/VYRoZcv9jI/TQAAAAAAAf//AAIAAQAAAAwAAAAWAAAAAgABAAMAEQABAAQAAAACAAAAAHjaY2BgYGQAgqtL1DlA9AOdhXNgNAA+VwY8AAA=') format('woff'),
url('iconfont.ttf') format('truetype'),
url('iconfont.svg#iconfont') format('svg');
font-weight: normal;
font-style: normal;
font-display: swap;
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-xiajiantou:before {
content: "\eb6d";
}
.icon-caidananniu1:before {
content: "\eac2";
}
.icon-xiaoxiduihuakuang-:before {
content: "\e671";
}
.icon-huabanwang:before {
content: "\e602";
}
.icon-tupian1:before {
content: "\e601";
}
.icon-zhuti_tiaosepan:before {
content: "\e604";
}
.icon-cangku:before {
content: "\e614";
}
.icon-erweima:before {
content: "\e65b";
}
.icon-liebiao:before {
content: "\e60d";
}
.icon-qianbao:before {
content: "\e645";
}
.icon-dunpaibaoxianrenzheng:before {
content: "\e600";
}
.icon-dengchu:before {
content: "\e603";
}
.icon-shutiao:before {
content: "\e727";
}
.icon-weibiaoti-:before {
content: "\e60e";
}
.icon-yanjing:before {
content: "\e857";
}
data: {
curfId: 4,
fruits: [{name: "苹果" ,id: 1},
{name: "西瓜" ,id: 2},
{name: "李子" ,id: 3},
{name: "梨" ,id: 4}
],
curfruitName:"梨" ,
title: "水果"
},
changeFruit(e){
console.log(e.detail.selectId);
console.log(e.detail.select);
// process();
},
下面的路径为组件所在位置(组件是键值对的形式,名字可以按自己的习惯取)
{
"component": true,
"usingComponents": {
"my_select":"/pages/components/test/test"
}
}
键的名字即为标签(可以说是自定义的)
完成以上步骤,就会出现一个简单的下拉框
出现下图即为成功
在线@font面生成器 — Transfonter
图一
图二
这样,icon的图标就会显示出来了
以上就是小编所讲的全部内容,希望各位大佬可以多多指教!!!