V-Calendar如何从API获取默认输入值

发布于 2025-02-08 01:00:17 字数 1921 浏览 2 评论 0原文

我正在使用VUE,V-Calendar库和Moment库。

我希望在渲染页面时,输入标签应从getapi()获得值,但不是。
我想这是因为启动和结束范围数据是“”。
因此,我尝试将数据分配到输入值并起作用。
但是我想知道为什么我应该将数据分配给输入值。

是否有一种不使用REF和使用V-Calendar属性的方法?

预先感谢!

这是下面我的模板代码,

<form class="form" @submit.prevent>
   <Vc-date-picker
       v-model="range"
       :masks="masks"
       is-range
       :min-date="today"
  >
  <template v-slot="{ inputValue, inputEvents, isDragging }">
      <div class="rangeInput">
          <div class="eachInputWrapper">
              <input
                  id="eachInput"
                  ref="startInput"
                  :class="isDragging ? 'text-gray-600' : 'text-gray-900'"
                  :value="inputValue.start"
                  v-on="inputEvents.start"
              />
          </div>
       </div>
   </template>
   </Vc-date-picker>
</form>

这是我的脚本代码

data(){
   return{
        range: {
            start: '',
            end:  '',
        },
    }
},
methods:{
    dateFormat(data){
        return moment(data).format("YYYY-MM-DD");
    },
    getAPI(){     
        this.$thisIsAPI(Id,Data).then((data)=>{
            this.range.start = this.dateFormat(data.fromDate);
            this.range.end = this.dateFormat(data.expireDate);
        });
    },
},
created(){
    this.getAPI();
}

这是我尝试的,并且输入标签在页面呈现时获取值。

getAPI(){     
        this.$thisIsAPI(Id,Data).then((data)=>{
            this.range.start = this.dateFormat(data.fromDate);
            this.range.end = this.dateFormat(data.expireDate);
        });
    this.$refs.startInput.value = this.dateFormat(this.botInfo.fromDt);
    this.$refs.endInput.value = this.dateFormat(this.botInfo.expireDt);
},

I'm using Vue, v-calendar library and moment library.

I want that when a page is rendered, a input tag should get a value from getAPI(), but it doesn't.
I guess it's because start and end in the range data is ''.
so I tried to assign data into the input value directly and it worked.
but I want to know why I should assign data in to input value directly.

Is there a way that doesn't use ref and using v-calendar properties?

Thanks in advance!

This is my template code below,

<form class="form" @submit.prevent>
   <Vc-date-picker
       v-model="range"
       :masks="masks"
       is-range
       :min-date="today"
  >
  <template v-slot="{ inputValue, inputEvents, isDragging }">
      <div class="rangeInput">
          <div class="eachInputWrapper">
              <input
                  id="eachInput"
                  ref="startInput"
                  :class="isDragging ? 'text-gray-600' : 'text-gray-900'"
                  :value="inputValue.start"
                  v-on="inputEvents.start"
              />
          </div>
       </div>
   </template>
   </Vc-date-picker>
</form>

This is my script code

data(){
   return{
        range: {
            start: '',
            end:  '',
        },
    }
},
methods:{
    dateFormat(data){
        return moment(data).format("YYYY-MM-DD");
    },
    getAPI(){     
        this.$thisIsAPI(Id,Data).then((data)=>{
            this.range.start = this.dateFormat(data.fromDate);
            this.range.end = this.dateFormat(data.expireDate);
        });
    },
},
created(){
    this.getAPI();
}

This is what I tried, and the input tag gets the value when the page is renderd.

getAPI(){     
        this.$thisIsAPI(Id,Data).then((data)=>{
            this.range.start = this.dateFormat(data.fromDate);
            this.range.end = this.dateFormat(data.expireDate);
        });
    this.$refs.startInput.value = this.dateFormat(this.botInfo.fromDt);
    this.$refs.endInput.value = this.dateFormat(this.botInfo.expireDt);
},

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文