在 vue 中使用 jquery ui 和时间选择器
Using jquery ui and time picker with vue
我正在尝试使用 jquery ui 设置 vue cli,但不知道如何使用 jquery ui 组件。我需要加载以下js文件
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js
https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js
https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-timepicker-addon.min.js
https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-sliderAccess.js
和
css 个文件
https://code.jquery.com/ui/1.10.0/themes/smoothness/jquery-ui.css
https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-timepicker-addon.min.css
让时间选择器工作。这是我测试功能的代码笔link。
https://codepen.io/cksachdev/pen/EJgGVR
关于我应该如何使用 vue-cli/webpack 配置加载它们的任何建议。
这是我目前尝试过的方法:
module: {
loaders: [
{ test: /\.css$/, loader: ['style-loader', 'css-loader'] },
{ test: /\.(jpe?g|png|gif)$/i, loader: 'file-loader' },
],
},
plugins: [
// eslint-disable-next-line no-undef
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
jQuery: 'jquery',
}),
],
resolve: {
alias: {
'jquery-ui': '../../../node_modules/jquery-ui/ui/widgets',
'jquery-ui-css': '../../../node_modules/jquery-ui/../../themes/base',
},
},
编辑 2: 我继续写了一个演示项目,您可以通过镜像来完成这个..
View the source code/repo here
同样,不确定您为什么要这样做,但 ^that^ 是(另一种)解决方案..
您可以在 'index.html' 文件中添加这些脚本和 css 文件 (public -> index.html),并像这样使用它:
编辑 1: 非常重要的是要注意没有理由需要导入(相当大)jQuery 甚至使用 jQuery。 Vue 生态系统有很多现有的选项来处理这样的事情......
vue2-timepicker and Vuetify timepicker(Vuetify 更像是一个完整的预样式化组件库)..
/* TIMEPICKER COMPONENT */
const VueTimepicker = {
template: "#vue-timepicker",
computed: {
id() {
// give the component a unique id/name
return "time-picker-" + this._uid;
}
},
mounted() {
$("#" + this.id).timepicker({
timeFormat: "HH:mm:ss:l"
});
}
};
/* VUE APP */
new Vue({
el: "#app",
components: {
VueTimepicker,
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-timepicker-addon.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-sliderAccess.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.0/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-timepicker-addon.min.css" />
<!-- ******************** -->
<!-- VUE APP -->
<!-- ******************** -->
<div id="app">
<div>
<div>
<span>Timepicker 1</span>
<vue-timepicker/>
</div>
<div style="margin-top: 20px;">
<span>Timepicker 2</span>
<vue-timepicker/>
</div>
</div>
</div>
<!-- ******************** -->
<!-- TIMEPICKER COMPONENT -->
<!-- ******************** -->
<script type="text/x-template" id="vue-timepicker">
<div>
<input type="text" :name="id" :id="id" value=" ">
</div>
</script>
我正在尝试使用 jquery ui 设置 vue cli,但不知道如何使用 jquery ui 组件。我需要加载以下js文件
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js
https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js
https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-timepicker-addon.min.js
https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-sliderAccess.js
和 css 个文件
https://code.jquery.com/ui/1.10.0/themes/smoothness/jquery-ui.css
https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-timepicker-addon.min.css
让时间选择器工作。这是我测试功能的代码笔link。 https://codepen.io/cksachdev/pen/EJgGVR
关于我应该如何使用 vue-cli/webpack 配置加载它们的任何建议。
这是我目前尝试过的方法:
module: {
loaders: [
{ test: /\.css$/, loader: ['style-loader', 'css-loader'] },
{ test: /\.(jpe?g|png|gif)$/i, loader: 'file-loader' },
],
},
plugins: [
// eslint-disable-next-line no-undef
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
jQuery: 'jquery',
}),
],
resolve: {
alias: {
'jquery-ui': '../../../node_modules/jquery-ui/ui/widgets',
'jquery-ui-css': '../../../node_modules/jquery-ui/../../themes/base',
},
},
编辑 2: 我继续写了一个演示项目,您可以通过镜像来完成这个..
View the source code/repo here
同样,不确定您为什么要这样做,但 ^that^ 是(另一种)解决方案..
您可以在 'index.html' 文件中添加这些脚本和 css 文件 (public -> index.html),并像这样使用它:
编辑 1: 非常重要的是要注意没有理由需要导入(相当大)jQuery 甚至使用 jQuery。 Vue 生态系统有很多现有的选项来处理这样的事情......
vue2-timepicker and Vuetify timepicker(Vuetify 更像是一个完整的预样式化组件库)..
/* TIMEPICKER COMPONENT */
const VueTimepicker = {
template: "#vue-timepicker",
computed: {
id() {
// give the component a unique id/name
return "time-picker-" + this._uid;
}
},
mounted() {
$("#" + this.id).timepicker({
timeFormat: "HH:mm:ss:l"
});
}
};
/* VUE APP */
new Vue({
el: "#app",
components: {
VueTimepicker,
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-timepicker-addon.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-sliderAccess.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.0/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.ui.timepicker.addon/1.4.5/jquery-ui-timepicker-addon.min.css" />
<!-- ******************** -->
<!-- VUE APP -->
<!-- ******************** -->
<div id="app">
<div>
<div>
<span>Timepicker 1</span>
<vue-timepicker/>
</div>
<div style="margin-top: 20px;">
<span>Timepicker 2</span>
<vue-timepicker/>
</div>
</div>
</div>
<!-- ******************** -->
<!-- TIMEPICKER COMPONENT -->
<!-- ******************** -->
<script type="text/x-template" id="vue-timepicker">
<div>
<input type="text" :name="id" :id="id" value=" ">
</div>
</script>