About the inheritance of $attrs

< H1 > the effect of typing according to the code in the vue document is inconsistent; < / H1 >
Vue.component("base-input", {
  inheritAttrs: false,
  props: ["label", "value"],
  template: `
    <label>
      {{ label }}
      <input
        v-bind="$attrs"
        v-bind:value="value"
        v-on:input="$emit("input", $event.target.value)"
      >
    </label>
  `
})
<base-input
  v-model="username"
  class="username-input"
  placeholder="Enter your username"
></base-input>
< H1 > Why did the class of class= "username-input" fall on the label tag? shouldn"t it fall on input? ask for advice < / H1 >
Mar.17,2021

take a look at the official document vm.$attrs :

vm.$attrs contains feature bindings in the parent scope that are not recognized (and obtained) as prop (except class and style ).

pay attention to the bold content in parentheses. $attrs does not contain class

.

Why should fall on input ? label is the root element ide/class-and-style.html-sharp%E7%94%A8%E5%9C%A8%E7%BB%84%E4%BB%B6%E4%B8%8A" rel=" nofollow noreferrer "> Class binds to Style

Menu