uni-app 组件小demo
留存一下,省的忘了。
1 2 | <!-- 子组件通过 $emit 控制父组件的事件 --> <!-- 父组件通过属性,给子组件传值 --> |
父组件引用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | < template > < view > < shuru :huizi="'姓名'" v-model="data" @input="cc" @click="zudianji"></ shuru > < view @click="houqu">获取一下看看</ view > </ view > </ template > < script > import shuru from '../../components/text_ipt/text_ipt.vue'; export default { components: { shuru }, data() { return { data: '' }; }, methods: { houqu() { console.log('demo', this.data); }, zudianji() { console.log('组件的点击'); }, cc(e) { console.log('看看cc有没有东西', e); } } }; </ script > |
子组件书写
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | < template > < view > < view class="tianxie-box" @tap="dianji"> < view class="tianxie-huizi">{{ huizi }}</ view > < input class="tianxie-heizi" :value="value" @input="input_nei($event.target.value)" :placeholder="'请输入' + huizi" type="text" /> </ view > </ view > </ template > < script > export default { name: 'tianxie', props: { // 灰字 huizi: { type: [String, Number], default: '' }, //黑字 hezi: { type: [String, Number], default: '' }, value: { type: [String, Number], default: '' } }, methods: { dianji() { this.$emit('click'); }, input_nei(e) { this.$emit('input', e); } } }; </ script > < style scoped lang="scss"> .tianxie-box { min-height: 180upx; width: 670upx; margin: 0 auto; box-sizing: border-box; padding-top: 40upx; border-bottom: 1px solid #f1f1f1; } .tianxie-huizi { height: 40upx; line-hegiht: 40upx; font-size: 28upx; font-family: PingFangSC-Regular, PingFang SC; font-weight: 400; color: #999999; } .tianxie-heizi { min-height: 50upx; line-height: 50upx; margin-top: 20upx; font-size: 36upx; font-family: PingFangSC-Regular, PingFang SC; font-weight: 400; color: #333333; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; width: 670rpx; } .tianxie-box1 { width: 670rpx; min-height: 180rpx; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; box-sizing: border-box; padding-top: 40rpx; border-bottom: 1px solid #f1f1f1; } .right_tip { width: 22rpx; height: 38rpx; } </ style > |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步