我正在为VueJS版本使用CoreUI模板,但是我不确定如何从以下链接获取CInput值:https://coreui.io/vue/demo/3.0-beta.1/#/forms/basic-forms,
我想像这样绑定输入值:https://vuejs.org/v2/guide/forms.html#Text
这是代码,我使用过v模型,但是看起来无法正常工作:
<template>
<div>
<p style="white-space: preline;">{{message}}</p>
<CForm>
<CInput
v-model="message"
label="Input is valid"
valid-feedback="Input is valid."
invalid-feedback="Please provide at least 4 characters."
value="Valid value"
:is-valid="validator"
/>
<CInput
label="Input is invalid"
valid-feedback="Thank you :)"
invalid-feedback="Please provide at least 4 characters."
:is-valid="validator"
/>
</CForm>
</div>
</template>
<script>
export default {
methods: {
validator(val) {
return val ? val.length >= 4 : false
}
}
}
</script>
答案 0 :(得分:1)
v-model
不适用于CInput
组件。根据他们的docs,您可以使用事件(update:value
,input
和change
)更新组件数据。示例:
<template>
<div>
<p style="white-space: preline;">{{message}}</p>
<CForm>
<CInput
label="Input is valid"
valid-feedback="Input is valid."
invalid-feedback="Please provide at least 4 characters."
:value="message"
@input="message = $event.target.value"
:is-valid="validator"
/>
<CInput
label="Input is invalid"
valid-feedback="Thank you :)"
invalid-feedback="Please provide at least 4 characters."
:is-valid="validator"
/>
</CForm>
</div>
</template>
<script>
export default {
data () {
return {
message: "",
}
},
methods: {
validator(val) {
return val ? val.length >= 4 : false
}
}
}
</script>