【发布时间】:2021-11-04 09:14:07
【问题描述】:
我正在尝试在我的页面中创建一个日期范围选择器,例如 this。以下是我的部分代码:
在 daterangepicker.blade.php 中
<span id="reportrange" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
<i class="fa fa-calendar"></i>
<span></span> <i class="fa fa-caret-down"></i>
</span>
在 app.js 中
Vue.loadScript("https://cdn.jsdelivr.net/momentjs/latest/moment.min.js")
.then(() => {
console.log('456');
Vue.loadScript("https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js")
.then(() => {
$(function() {
console.log('789');
var start = moment().subtract(29, 'days');
var end = moment();
function cb(start, end) {
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
cb(start, end);
});
})
.catch(() => {
// Failed to fetch script
});
})
.catch(() => {
// Failed to fetch script
});
问题是 daterangepicker 仅在我使用 Ctrl+F5 刷新页面时才有效。一旦我只使用 F5 正常刷新页面,它就会显示为 this。
在控制台中,当我正常刷新页面时,它会非常快地加载并立即显示 console.log,但是当我使用硬刷新时,console.log 我输入的消息需要相当长的时间。
【问题讨论】:
-
看起来你可以混合使用 jQuery 和 vue you should avoid doing this
-
@Jon P 你分享的链接没有讨论为什么你不应该混合使用 jQuery 和 Vue,而只是为了展示如果你想要如何混合(?)。那么这(混合 jQuery 和 Vue)是真正的问题还是有其他原因?感谢您的回答
-
就 jQuery 而言,它与 Vue、React 等基本相同,你有两个框架使用非常不同的方法与 DOM 交互,而且它们通常不能很好地协同工作。你最好使用像 innologica.github.io/vue2-daterange-picker , npmjs.com/package/vue2-datepicker 或 morioh.com/p/e4968ba0aca0 之类的 vue 组件
-
感谢您分享的链接,将尝试一下
标签: javascript html css vue.js laravel-blade