在本文中你将收获
在根目录新建components文件夹,建立cell 文件夹,右击创建cell的Component组件
页面的xxx.json ,usingComponent注册
"usingComponents": {
"item":"/components/item/item"
}
/* pages/com/com.wxss */
.cell{color: tomato;
}
.mycell{color: #f70;line-height: 120rpx !important;
}
/* 选项 */options:{/* 样式隔离:apply-shared 父影响子shared 父子相互影响 isolated 相互隔离*/styleIsolation:'isolated',},//通过组件的外部类实现父组件控制自己的样式externalClasses:["cell-class"],
|
|
我是cell组件
/* 选项 */options:{//允许多个插槽multipleSlots:true,},
.cell{height: 88rpx;line-height: 88rpx;border-bottom: 1rpx solid #cccccc;
}
放假 快点到来
|
我是cell组件
/* 选项 */options:{//允许多个插槽multipleSlots:true,},
.cell{height: 88rpx;line-height: 88rpx;border-bottom: 1rpx solid #cccccc;
}
🐱👓 🐱🚀 放假 快点到来
|
🎉 🐱 做核酸 今天要做
|
{{title}} {{num}}
// components/cell/cell.js
Component({/* 选项 */options:{/* 样式隔离:apply-shared 父影响子shared 父子相互影响 isolated 相互隔离*/styleIsolation:'isolated',//允许多个插槽multipleSlots:true,},/*** 组件的属性列表*/properties: {title:{type:String,value:""},num:{type:Number,value:1}},/*** 组件的初始数据*/data: {//定义组件自己的数据countcount:1},/*** 组件的方法列表*/
})
{5}}"> |
|
{{title}} {{count}}
// components/cell/cell.js
Component({/* 选项 */options:{/* 样式隔离:apply-shared 父影响子shared 父子相互影响 isolated 相互隔离*/styleIsolation:'isolated',//允许多个插槽multipleSlots:true,},/*** 组件的属性列表*/properties: {title:{type:String,value:""},num:{type:Number,value:1}},/*** 组件的初始数据*/data: {//定义组件自己的数据countcount:1},lifetimes:{//在组件生命周期attached挂载更新countattached(){console.log(this.data);//count 的值为父组件传递的num值this.setData({count:this.data.num})}},/*** 组件的方法列表*/methods: {tapHd(){this.setData({count:this.data.count+5})//发送一个事件this.triggerEvent("cellclick",this.data.count)}}
})
{{title}} {{count}}
{url}}" open-type="{{openType}}" bindtap="itemclick">{icon}}">{icon}}" mode="aspectFill"/> {title}}">{{title}} {!showrslot}}">{{tip}} {badge}}">{badge===true}}" class="dot"> {{badge}}
/* components/item/item.wxss */
.item{line-height: 88rpx;display: flex;align-items: center;justify-content: space-between;
}
.icon{margin-left: 30rpx;margin-right: 30rpx;height: 100%;display: flex;align-items: center;
}
.icon image{width: 60rpx;height: 60rpx;
}
.content{padding: 0 30rpx;border-bottom: 1rpx solid #ccc;display: flex;flex: 1;
}
.title{flex: 1;color: #333;font-size: 35rpx;
}
.right{display: flex;align-items: center;
}
.right .arrow{height: 25rpx;width: 25rpx;border-top: 3rpx solid #999;border-right: 3rpx solid #999;transform: rotate(45deg);
}
.tip{color: #999;font-size: 28rpx;
}
.dot{height: 15rpx;width: 15rpx;background-color: #f30;margin-left: 15rpx;border-radius: 50%;
}
.redbadge{font-size: 20rpx;padding: 5rpx;background-color: #f30;width: 30rpx;max-height: 30rpx;line-height: 30rpx;color: #fff;text-align: center;margin-left: 15rpx;border-radius: 20rpx;
}
{"usingComponents": {"cell": "/components/cell/cell"}
}
- {true}}" tip="10条消息未读">
- {12}}" tip="12条消息未读">
- {true}}">
-
插槽title
- {true}}" itemclass="myitem">
.myitem{line-height: 120rpx !important;background-color: #f0f0f0;
}
【Vue】描述项目中两个功能模块的业务(一点见解)
【Git】Git基础操作一文详解,入门易懂(附图和案例
【Vue3】整理的一些Vue3知识点和案例(Vue3 获取窗口宽和高)