v-model not working with in Vue 3?
P粉806834059
P粉806834059 2023-08-29 20:16:20
0
1
395

为什么在下面的示例中 v-model 没有绑定到我的输入? 有限制吗?

 

P粉806834059
P粉806834059

reply all (1)
P粉081360775

Vuev-modelWorks great for native elements.

But it obviously doesn't work with

Your code generation

A very quick solution is to implementvaluebinding directly.

:value="item[header.field]" @input="item[header.field] = $event.target.value"

But you will need to update the component accordingly to usevalueinstead ofmodelValue.

renew

The workaround usingv-model:valueonly works one way, the same as:value.

const { createApp, ref } = Vue const config = ref({ headers: [ { field: 'id', label: 'Id', component: { type: 'input' } }, { field: 'name', label: 'Name', component: { type: 'input' } }, // more configs for radio buttons and other custom components ], data: [ { id: 1, name: 'foo' }, { id: 2, name: 'bar' } ] }) const App = { setup() { return { config, test: 1 } } } const app = createApp(App) app.mount('#app')
#app { line-height: 1.75; } [v-cloak] { display: none; }
{{ header.label }}
{{ config.data }}
v-model test:
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!