CoreUI Vuejs 输入表单

CoreUI Vuejs input form

我正在为 VueJS 版本使用 CoreUI 模板,但我不确定如何从此 link 获取 CInput 值:https://coreui.io/vue/demo/3.0-beta.1/#/forms/basic-forms

我想像这样绑定输入值:https://vuejs.org/v2/guide/forms.html#Text

这是代码,我使用了 v-model 但它看起来无法工作:

<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>

v-model 不适用于 CInput 组件。根据他们的 docs,您可以使用事件(update:valueinputchange)来更新您的组件数据。示例:

<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>