Vue dynamic binding model failed

for example,

currently under this vue component, there is a variable key whose value is tel,. I want an input component to bind to different variables according to this key value. For example, when key is a tel string, bind to "create.form."+key, that is, bind to create.form.key. This is dynamic binding. Excuse me, can this binding be implemented in vue?

<Input :v-model=""create.form."+a"></Input>

where an is" tel"

or even

<Input :v-model=""create.form.tel""></Input>

after binding, the actual modification of create.form.tel data is not reflected in the input input box, indicating that it is not bound. What is the reason? Does vue not allow this binding?

Mar.06,2021

this question can be solved with computed , the following code

  <input v-model='com'>
  data () {
    return {
      type: 'a',
      form: {
        a: 123,
        b: 321
      }
    }
  },
  computed: {
    com () {
      return this.form[this.type]
    }
  },
  created () {
    setTimeout(() => {
      this.type = 'b'
    }, 1000)
  }

(Why do you want to change the key dynamically instead of the value dynamically?


you actually bind to a string like this

Grammatical sugar of

Menu