美文网首页
datepicker使用

datepicker使用

作者: zhanggongzi | 来源:发表于2018-09-26 15:12 被阅读0次

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue flatpickr demo</title>
<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/flatpickr/4.5.0/flatpickr.css">
<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/flatpickr/4.5.0/ie.css">
<script type="text/javascript" src="https://cdn.bootcss.com/vue/2.5.7/vue.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/flatpickr/4.5.0/flatpickr.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/flatpickr/4.5.0/l10n/zh.js"></script>
<script type="text/javascript">
flatpickr.localize(flatpickr.l10ns.zh);
</script>
</head>
<body>
<script type="text/javascript">
var component = {
props:["model","placeholder","mode","time","seconds","options","style"],
template:"<input :placeholder='placeholder' :style='style' />",
data:function(){
return {
instance:{}
};
},
created:function(){
},
mounted:function(){
var self = this;
this.instance = self.el.flatpickr({ mode:this.mode || "single", enableTime:this.time, enableSeconds:this.seconds, onChange:function(date,value){ self.el.value = value;
self.emit("change",value); } }); // this.instance = flatpickr(this.el, .extend({ // mode:this.mode || "single", // enableTime:this.time, // enableSeconds:this.seconds, // onChange:function(date,value){ // self.el.value = value;
// self.$emit("change",self.model,value);
// }
// },this.options || {}));
},
methods:{
}
}
Vue.component("datepicker",component);
</script>
<div id="app">
<datepicker :model="date1" :placeholder="placeholder" time="true" @change="setVal"></datepicker>
<datepicker :model="date2" :placeholder="placeholder" @change="setVal2"></datepicker>
<datepicker :model="date1" v-on:change="setVal" time="true" seconds="true" :style="{width:'200px'}"></datepicker>
<datepicker :model="date1" v-on:change="setVal" mode="range" :style="{width:'250px'}"></datepicker>
<datepicker :model="date1" v-on:change="setVal" mode="multiple" :style="{width:'500px'}"></datepicker>
</div>
<script type="text/javascript">
var app = new Vue({
el:'#app',
data:{
date1:'',
date2:'',
placeholder:'选择日期'
},
methods:{
setVal:function(val){
this.date1 = val;
},
setVal2:function(val){
this.date2 = val;
}
}
})
</script>
</body>
</html>

相关文章

网友评论

      本文标题:datepicker使用

      本文链接:https://www.haomeiwen.com/subject/yuadoftx.html