前提:題主之前只是隨意的封裝,項目統一ui,然后只實現了父組件拿子組件值,沒有實現父組件修改子組件的值,仔細看了文檔才知道用model的作用,直接上代碼
Vue.component("base-input", {
model: {
prop: "val",
event: "input"
},
props: {
val: [String, Number]
},
template: `
<input
type="text"
v-bind:value="val"
@input="$emit('input', $event.target.value)"
>
`
});
父組件使用
<base-input v-model=""></base-input>
原因系解:等作者補坑
