输入CHECBOX V-MODEL不使用异步数据检查
我有一个开始,从数据库中获取数据。它可以选择检查输入是否为true或false。但是问题是没有检查其何时为。我尝试了:检查并起作用,但是由于具有两种方式绑定的
代码:
<input type="checkbox" v-model="data">
const data = ref(false)
onBeforeMount(async () => {
await data = fetchingData()
})
我没有编写孔代码,因此我需要V型模型,因为它在另一台计算机上的代码是从HEARD上写的。但是我的台词和v-Model没有检查。如果我使用:检查它的工作就像魅力一样,
也许这是一个新秀错误,但没有使用:检查:更改我没有看到任何解决方案。
I have a component that at the start of it, fetchs data from database. And it supose to check the input if the value is true or false. But the problem is that is not checking when its true. I tried :checked and it works, but i need the v-model because of the two way binding
code:
<input type="checkbox" v-model="data">
const data = ref(false)
onBeforeMount(async () => {
await data = fetchingData()
})
I didnt write the hole code, because the code its on another computer, this was from head. But i am having poblems with v-model not checking. If i use :checked it works like a charm
Maybe this is a rookie mistake, but without using :checked with :change i am not seing any solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
data.value
而不是数据
进行反应性。为了演示目的,我将值直接分配为true
。您可以用API呼叫代码替换。实时演示:
You should use
data.value
instead ofdata
for the reactivity. For the demo purpose I am directly assign the value astrue
. You can replace that with the API call code.Live Demo :
我认为这不是复选框,但是您应该使用
.value。
写入ref
时。否则,您会失去反应性,而V模型将不起作用。希望这会有所帮助。
I do not think it is the checkbox, but that you should use the
.value
when you write to aref
. Otherwise you loose the reactivity and v-model will not work.Hope this helps.