在使用子組件時如果向子組件傳入非props的屬性,這些屬性會被這個子組件的根屬性所繼承而不會作用到子組件上
如果想要這些屬性在子組件中生效,可以在子組件中禁用屬性繼承
export default defineComponent({ inheritAttrs: false })
之后在子組件的模板中綁定$attr屬性后,即可支持傳入的非prop屬性
<input type="text" v-bind="$attrs" />
此時我們從父組件傳入一個input的默認屬性placeholder
<component-input placeholder="請輸入"></component-input>