ion-datetime 无法正确更新小时

huangapple go评论50阅读模式
英文:

ion-datetime unable to update the hours correctly

问题

在我的Vue 3应用程序中,我有以下名为"ion-datetime"的元素,其分配的模态值为"mytime",它只是一个空的"ref()"。

<ion-datetime-button datetime="datetime1"></ion-datetime-button>
<ion-modal :keep-contents-mounted="true">
   <ion-datetime 
   id="datetime1" 
   :value="mytime"
   @ion-change="mytime = $event.target.value, check()"
   />
</ion-modal>

我使用"check()"函数在发生更改时将"mytime"记录到控制台。

const mytime = ref()
const check = () => {
  console.log(mytime.value)
}

当我更新日期时,"mytime"会更新得很好,但当我尝试更新时间时,根据我的控制台,没有发生任何变化。为什么会这样?

英文:

In my vue3 application I have the following "ion-datetime" with the assigned modal value called "mytime", which is merely an empty "ref()".

   &lt;ion-datetime-button datetime=&quot;datetime1&quot;&gt;&lt;/ion-datetime-button&gt;
    &lt;ion-modal :keep-contents-mounted=&quot;true&quot;&gt;
       &lt;ion-datetime 
       id=&quot;datetime1&quot; 
       :value=&quot;mytime&quot;
       @ion-change=&quot;mytime = $event.target.value, check()&quot;
       /&gt;
    &lt;/ion-modal&gt;

I use the function "check()" to console.log the "mytime" whenever a change occurs

const mytime = ref()
const check = () =&gt; {
  console.log(mytime.value)
}

When i update the date "mytime" is updated just fine but whenever i try updating time no changes occur according to my console.
Why is that?

答案1

得分: 1

&lt;ion-datetime-button datetime=&quot;datetime1&quot;&gt;&lt;/ion-datetime-button&gt;
&lt;ion-modal :keep-contents-mounted=&quot;true&quot;&gt;
  &lt;ion-datetime
    id=&quot;datetime1&quot;
    :value=&quot;mytime&quot;
    @ion-change=&quot;(e)=&gt;{(mytime = e.target.value); check()}&quot;
  /&gt;
&lt;/ion-modal&gt;

我建议直接从变更事件中获取事件,而不是$event

英文:
&lt;ion-datetime-button datetime=&quot;datetime1&quot;&gt;&lt;/ion-datetime-button&gt;
&lt;ion-modal :keep-contents-mounted=&quot;true&quot;&gt;
  &lt;ion-datetime
    id=&quot;datetime1&quot;
    :value=&quot;mytime&quot;
    @ion-change=&quot;(e)=&gt;{(mytime = e.target.value); check()}&quot;
  /&gt;
&lt;/ion-modal&gt;

I would recommend getting the event directly from the change event and not $event

huangapple
  • 本文由 发表于 2023年5月11日 04:31:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76222343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定