vue中 input type=date组件封装及调用

发布时间:2024-11-21 18:17

JavaScript框架React或Vue:熟悉其组件化思维 #生活技巧# #工作学习技巧# #编程语言学习路径#

最新推荐文章于 2024-09-05 09:34:10 发布

xiejunna 于 2019-01-25 12:08:04 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

封装组件vue

<template> <div class="inputItem"> <div class="leftText">{{textName}}</div> <div class="rightText"> <input type="date" class="inputstyle" v-on:change="dateChanged" > </div> </div> </template> <script> export default { name: "InputDate", props: ["textName"], data() { return {}; }, mounted() {}, methods: { //监听日期改变函数 dateChanged: function($event) { this.$emit("dateChanged", $event); //将值放在自定义的事件函数中作为参数 } }, computed: {} }; </script> <style scoped> input:focus { outline: none; border: 1px solid #fff; } .inputItem { width: 100%; height: 60px; font-size: 18px; text-indent: 10px; letter-spacing: 10px; display: flex; display: -webkit-flex; flex-direction: row; flex-wrap: nowrap; justify-content: center; align-items: center; align-content: center; border-bottom: 1px solid #eceef1; } .leftText { width: 15%; padding-left: 1%; color: #757575; overflow: hidden; word-break:keep-all; white-space:nowrap; } .rightText { width: 84%; } .inputstyle { width: auto; min-width: 50%; border: none; outline: none; text-indent: 3px; letter-spacing: 3px; color: #757575; /* border-bottom: 1px solid #6a7c9f; */ } </style>

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172

调用组件vue

<template> <div class="main" :style="{'height':getClientHeight1}"> <div class="menuContainer"> <div class="menuItem"> <span class="exportBarText"> test > <b>test</b> </span> </div> <div class="menuItem" id="menuItem"></div> </div> <div class="dataList" :style="{'height':getClientHeight2}"> <div class="reactDatalist"> <InputDate textName="日期" v-on:dateChanged="dateChanged($event)"></InputDate> <div class="btnContainer"> <button class="btn" @click="clicking($event)">确定</button> </div> </div> </div> <toast v-show="toastShow" :msg="toastMsg" v-on:closeToast="closeToast($event)"></toast> </div> </template> <script> import toast from "../basicComponents/Toast"; import InputDate from "../basicComponents/InputDate"; export default { components: { InputDate, toast }, data() { return { toastShow: false, toastMsg: "", date:"", }; }, methods: { closeToast($event) { console.log("closeToast"); this.toastShow = false; }, showToast: function(content) { let that = this; that.toastShow = true; that.toastMsg = content; setTimeout(function() { that.toastShow = false; }, 2000); }, dateChanged:function ($event) { console.log($event.target.value) }, clicking:function ($event) { console.log("pushKafka"); console.log(this.$refs.inputDate) } }, mounted: function(e) { console.log("mounted query Terminal Data"); }, computed: { getClientHeight1: function() { return tools.getClientHeight() - 100 + "px"; }, getClientHeight2: function() { return tools.getClientHeight() - 160 + "px"; }, saveTerminalListData: function(list) { return this.$store.commit("TerminalList", list); } } }; </script> <style scoped> .menuContainer { width: 100%; height: 60px; line-height: 60px; display: flex; display: -webkit-flex; flex-direction: row; flex-wrap: nowrap; justify-content: center; align-items: center; align-content: center; } .menuItem { width: 50%; height: 60px; } #menuItem { position: relative; padding-left: 24%; } .main { width: 100%; float: left; font-family: NotoSansHans-Light, Arial, Helvetica, sans-serif; } .dataList { position: relative; width: 100%; background: #f0f3fa; } .reactDatalist { position: absolute; top: 7%; left: 50%; width: 97%; min-height: 400px; transform: translateX(-50%); border-radius: 8px; box-shadow: 0px 0px 12px -2px #2a3853; overflow: auto; background: #fff; } .exportBarText { width: 300px; height: 60px; display: inline-block; padding-left: 20px; color: #94a0b9; } .btnContainer{ width: 100%; height: 60px; margin-top: 20px; font-size: 18px; text-indent: 10px; letter-spacing: 10px; display: flex; display: -webkit-flex; flex-direction: row; flex-wrap: nowrap; justify-content: center; align-items: center; align-content: center; } .btn{ width: 35%; height: 45px; font-size: 18px; text-indent: 10px; letter-spacing: 10px; } </style>

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157

网址:vue中 input type=date组件封装及调用 https://www.yuejiaxmz.com/news/view/177673

相关内容

vue技巧
巧用两个type=range input实现区域范围选择 « 张鑫旭
利用css3修改input[type=radio]样式
input的type为file时,判断上传文件的类型和大小
input type = file 在部分安卓手机上无法调起摄像头和相册
修改 input type=file 的样式的最简单方法
CSS小技巧——去除input[type=number]的默认样式
input的type=file上传图片简单使用
html 日期 年月 年月日 及默认样式
基于Java+SpringBoot+Vue+HTML5膳食营养健康网站(源码+LW+调试文档+讲解等)/膳食搭配/营养建议/健康生活/网站推荐/营养学/饮食指南/健康饮食/营养食谱/膳食计划/健康膳食

随便看看