英文:
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()".
<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>
I use the function "check()" to console.log the "mytime" whenever a change occurs
const mytime = ref()
const check = () => {
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
<ion-datetime-button datetime="datetime1"></ion-datetime-button>
<ion-modal :keep-contents-mounted="true">
<ion-datetime
id="datetime1"
:value="mytime"
@ion-change="(e)=>{(mytime = e.target.value); check()}"
/>
</ion-modal>
我建议直接从变更事件中获取事件,而不是$event
。
英文:
<ion-datetime-button datetime="datetime1"></ion-datetime-button>
<ion-modal :keep-contents-mounted="true">
<ion-datetime
id="datetime1"
:value="mytime"
@ion-change="(e)=>{(mytime = e.target.value); check()}"
/>
</ion-modal>
I would recommend getting the event directly from the change event and not $event
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论