[javascript] js判断对象类型typeof与instanceof解决elementui时间插件默认时间问题
2021/6/17 20:29:09
本文主要是介绍[javascript] js判断对象类型typeof与instanceof解决elementui时间插件默认时间问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
在页面上有一个时间插件 , 默认是没有绑定初始时间的 , 当需要绑定初始时候时 , 只能给它赋值当前日期的Date对象
但是在调用接口的时候 , 要求传递的是一个指定格式的字符串 , 需要把Date对象转成时间字符串 , 这个时候就需要判断类型了
typeof 一般只能返回如下几个结果:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。无法指定是Date类型 , 因此这里需要使用instanceof
用法是console.log(xxx instanceof Date) 这个语句会返回true或者false ,来判断对象类型
在elementui下给时间默认值这样用 , html部分
<el-date-picker v-model="pickTime" align="right" type="date" placeholder="选择日期" value-format="yyyyMMdd" :picker-options="pickerOptions"> </el-date-picker>
绑定的pickTime , 在data里给一个初始值 pickTime:new Date(),
在进行搜索查询函数里进行类型判断 , 并且转换一下 , 格式转换函数在上一篇文章有
getKeywordsList: function () { let _this = this; let data={}; if(this.keywordSearchKey!=""){ data.word=this.keywordSearchKey; } if(this.pickTime instanceof Date){ data.dt=this.formateTime(this.pickTime); } if(this.pickTime != "" && !(this.pickTime instanceof Date)){ data.dt=this.pickTime; } $.get('index.php?r=media/getkeywordsdata',data, function (rs) { let res= JSON.parse(rs); _this.keywordsList=res.result.rows; _this.keywordCount=res.result.total; _this.keywordSearchCount=res.result.total; _this.displayAll(); _this.fullscreenLoading=false; }) },
这篇关于[javascript] js判断对象类型typeof与instanceof解决elementui时间插件默认时间问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-02springboot项目无法注册到nacos-icode9专业技术文章分享
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)