vux Datetime组件初始化赋值

解决办法,刷新组件,通过v-if来创建新的组件 

<template>
  <div>
    <div class="common">
      <group>
        <datetime v-model="uploadTime" title="上传时间" @on-change="changeUpload" placeholder="请选择上传时间" v-if='hackReset'></datetime>
      </group>
    </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      uploadTime: "", //上传时间
      hackReset: true
    };
  },

  components: {},

  mounted() {
    // 获取当前日期
      this.getDate();
  },

  methods: {
    // 获取当前日期
    getDate() {
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      if (month < 10) {
        month = "0" + month;
      }
      if (day < 10) {
        day = "0" + day;
      }
      this.uploadTime = year + "-" + month + "-" + day;
      this.hackReset = false;
      this.$nextTick(() => {
        this.hackReset = true;
      });
    },
    changeUpload(value) {
      console.log("ssdd", value);
      this.uploadTime = value;
    },
  },

  computed: {}
};
</script>
<style lang='less' scoped>
.common {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  margin: 0 1rem;
}
.btn {
  width: 92%;
  margin: 0 4%;
  padding: 10px 0;
  background: #2d8cf0;
  text-align: center;
  border-radius: 4px;
  font-size: 18px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #ffffff;
}
</style>

猜你喜欢

转载自blog.csdn.net/yuan_jlj/article/details/104694467