张卓
2022-09-29 4ef1c909df36c48f7f040e9ec408fc15e6745e71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<template>
  <el-date-picker
    v-model="value1"
    size="inputSize"
    type="datetime"
    placeholder="选择日期时间"
    value-format="yyyy-MM-dd HH"
  />
</template>
 
<script>
// 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
// 例如:import《组件名称》from'《组件路径》';
 
export default {
// import 引入的组件需要注入到对象中才能使用
  components: {},
  props: {
    value1: String,
    inputSize: String
  },
  data() {
    // 这里存放数据
    return {
      newValue1: ''
    }
  },
  // 计算属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {
    value1(nv, ov) {
      console.log(nv, ov)
      if (nv) {
        console.log(!nv)
        this.newValue1 = nv
        this.sendPicker()
      }
    }
  },
  // 生命周期 - 创建完成(可以访问当前 this 实例)
  created() {
    // this.currentHour()
  },
  // 生命周期 - 挂载完成(可以访问 DOM 元素)
  mounted() {
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    sendPicker() {
      console.log('子传父')
      this.$emit('sendPickerChild', this.newValue1)
    },
    // 当前时间份初始化
    currentHour() {
      var aData = new Date()
      var month = aData.getMonth() < 9 ? '0' + (aData.getMonth() + 1) : aData.getMonth() + 1
      var date = aData.getDate() <= 9 ? '0' + aData.getDate() : aData.getDate()
      var hour = aData.getHours() <= 9 ? '0' + aData.getHours() - 1 : aData.getHours() - 1
      var currentDate = aData.getFullYear() + '-' + month + '-' + date + ' ' + hour
      this.value1 = currentDate.toString()
      // this.newValue1 = currentDate.toString()
      console.log('小时组件回调数据')
      console.log(this.value1)
      // this.sendPicker()
    }
  } // 如果页面有keep-alive缓存功能,这个函数会触发
}
</script>
<style scoped>
 
</style>