本篇文章為大家展示了如何在vue中使用laydate時(shí)間插件,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
成都創(chuàng)新互聯(lián)專注于王益網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供王益營(yíng)銷型網(wǎng)站建設(shè),王益網(wǎng)站制作、王益網(wǎng)頁(yè)設(shè)計(jì)、王益網(wǎng)站官網(wǎng)定制、小程序制作服務(wù),打造王益網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供王益網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
在vue中使用laydate
在vue組件中npm install laydate,然后在vue組件中直接引入:
import laydate from 'laydate'
然后在mounted中調(diào)用:
laydate.now();
發(fā)現(xiàn)chrome瀏覽器控制臺(tái)中報(bào)錯(cuò),laydate is not defined,然后把laydate.js放在靜態(tài)資源里面引入:
import laydate from '../../static/js/laydate.js'
發(fā)現(xiàn)chrome瀏覽器控制臺(tái)中依然是報(bào)錯(cuò),laydate is not defined,然后在html入口文件中引入:
<script src="./src/static/js/laydate.js"></script>
發(fā)現(xiàn)chrome瀏覽器控制臺(tái)中不報(bào),laydate is not defined,但是又報(bào)另外一個(gè)錯(cuò)誤:require is not defined,查看原碼發(fā)現(xiàn)是因?yàn)閘aydate.js中在引用css樣式表時(shí)未定義:require('./need/laydate.css');require('./skins/default/laydate.css');
最后使用laydate打包構(gòu)建后的文件:dist/laydate/laydate.min.js,把laydate.min.js和css粘貼到src/static/路徑下,注意js和css結(jié)構(gòu)不要改變
<script src="./src/static/laydate/laydate.min.js"></script>
然后在chrome瀏覽器中成功打印出了laydate.now()的值:2018-10-21
然后使用import方式引入laydate.min.js:
import laydate from '../../static/laydate/laydate.min.js'
chrome控制臺(tái)里有報(bào)錯(cuò):laydate.now is not a function
原因時(shí)laydate.min.js是直接把laydate對(duì)象注冊(cè)到了window上,本身并沒有export default laydate出口,所以不能使用這種方式引用,應(yīng)該使用:
import '../../static/laydate.min.js'
這樣引用后,chrome中成功打印laydate.now(); 2018-10-21
或者在入口文件index.html中使用CDN加速方式引入laydate.min.js也是可以的:
<script src="https://cdn.jsdelivr.net/npm/laydate@1.0.7/dist/laydate.min.js"></script>
當(dāng)然,如果項(xiàng)目中只是個(gè)別地方是使用到時(shí)間插件,建議采用import方式引入
laydate.min.js時(shí)間插件在vue組件中的使用方式
<template> <div id="laydateIndex"> <div class="input-item"> <label for="">請(qǐng)選擇時(shí)間:</label> <input type='text' name='houseChangeTime' placeholder='請(qǐng)選擇日期' class='form-control' onclick="laydate({ istime: true, format: 'YYYY/MM/DD hh:mm:ss' })" /> </div> <div class="input-item"> <label for="">開始時(shí)間:</label> <input type="text" name="" id="begintime" placeholder='請(qǐng)選擇日期'> </div> <div class="input-item"> <label for="">結(jié)束時(shí)間:</label> <input type="text" name="" id="endtime" placeholder='請(qǐng)選擇日期'> </div> </div> </template>
<script> import '../../assets/js/laydate.min.js' export default { name: 'laydateIndex', data () { return { begintime: '', endtime: '', start_time: '', } }, methods: { setBeginTime () { var _this = this; var mintime = laydate.now(0, 'YYYY-MM-DD hh:mm:ss'); _this.$data.begintime = mintime; _this.$data.endtime = mintime; var begintiem_options = { elem: '#begintime', format: 'YYYY-MM-DD hh:mm:ss', // 分隔符可以任意定義 event: 'click', //觸發(fā)事件 istime: true, //是否開啟時(shí)間選擇 isclear: true, //是否顯示清空 issure: true, //是否顯示確認(rèn) festival: true, //是否顯示節(jié)日 min: mintime, //最小日期 max: '2099-12-31 23:59:59', //最大日期 start: mintime, //開始日期 fixed: true, //是否固定在可視區(qū)域 zIndex: 99999999, //css z-index choose: function(dates) { // 選擇日期完畢的回調(diào) endtime_options.start = dates; endtime_options.min = dates; _this.$data.begintime = dates; _this.$data.endtime = dates; } }; var endtime_options = { elem: '#endtime', format: 'YYYY-MM-DD hh:mm:ss', // 分隔符可以任意定義 event: 'click', //觸發(fā)事件 istime: true, //是否開啟時(shí)間選擇 isclear: true, //是否顯示清空 issure: true, //是否顯示確認(rèn) festival: true, //是否顯示節(jié)日 min: _this.$data.begintime, //最小日期 max: '2099-12-31 23:59:59', //最大日期 start: _this.$data.begintime, //開始日期 fixed: true, //是否固定在可視區(qū)域 zIndex: 99999999, //css z-index choose: function(dates) { // 選擇日期完畢的回調(diào) // this.begintiem_options = dates; } }; laydate(begintiem_options); laydate(endtime_options); }, initPage () { var _this = this; _this.setBeginTime(); }, }, mounted () { this.initPage(); }, } </script>
上述內(nèi)容就是如何在vue中使用laydate時(shí)間插件,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
新聞標(biāo)題:如何在vue中使用laydate時(shí)間插件
地址分享:http://aaarwkj.com/article12/ggphdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、微信公眾號(hào)、網(wǎng)站收錄、網(wǎng)站導(dǎo)航、搜索引擎優(yōu)化、網(wǎng)站設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)