当前位置:网站首页>自定义组件的 v-model
自定义组件的 v-model
2022-07-02 02:42:00 【一加一不是二】
vue官网定义:
双向绑定
<input :value="something" @input="something = $event.target.value">
语法糖
<input v-model="something">
所以
<custom-input v-model="something"></custom-input>
在自定义组件中相当于
<custom-input :value="something" @input="something = $event.target.value">
</custom-input>
例子
父组件:
<template>
<el-form ref="form">
<el-form-item label="部门:">
<frame-select v-model="form.depidProp"></frame-select>
</el-form-item>
</el-form>
</template>
<script>
import frameSelect from './component/frameSelect.vue'
export default {
components: { frameSelect },
data() {
return {
form: {
depidProp:''
},
}
},
methods: { }
}
</script>子组件
<template>
<el-select v-model="modelValue" @change="changeOrgList">
<el-option v-for="item in orgLevelList"
:label="item.name" :value="item.name" :key="item.id">
</el-option>
</el-select>
</template>
<script>
export default {
props: {
//value名
modelValue: {
type: [String,Number],
default: ''
},
},
data() {
return {
orgLevelList: [{id:1,name:'组织部'},{id:2,name:'人事部'},{id:3,name:'技术部'}]
}
},
model: {
prop: 'modelValue',//value名
event: 'changeOrgList',//子组件要更新父组件值需要注册的方法
},
methods: {
changeOrgList(val) {
this.$emit('changeOrgList', val)
}
}
}
</script>边栏推荐
- 【无标题】
- Connected block template and variants (4 questions in total)
- Mongodb base de données non relationnelle
- Which kind of sports headphones is easier to use? The most recommended sports headphones
- Infix expression to suffix expression (computer) code
- Software development life cycle -- waterfall model
- [staff] the direction of the symbol stem and the connecting line (the symbol stem faces | the symbol stem below the third line faces upward | the symbol stem above the third line faces downward | the
- [road of system analyst] collection of wrong topics in enterprise informatization chapter
- Set status bar color
- 附加:信息脱敏;
猜你喜欢

批量检测url是否存在cdn—高准确率

An analysis of circuit for quick understanding

Coordinatorlayout + tablayout + viewpager2 (there is another recyclerview nested inside), and the sliding conflict of recyclerview is solved
![[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)](/img/98/956d8abbccceb1aae47e25825bc63d.jpg)
[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)

QT implementation interface jump

Software development life cycle -- waterfall model

Analysis of FLV packaging format

Share the basic knowledge of a common Hongmeng application

Deployment practice and problem solving of dash application development environment based on jupyter Lab
![[staff] the direction of the symbol stem and the connecting line (the symbol stem faces | the symbol stem below the third line faces upward | the symbol stem above the third line faces downward | the](/img/fe/d97b25f702bbc05f941d08147259e0.jpg)
[staff] the direction of the symbol stem and the connecting line (the symbol stem faces | the symbol stem below the third line faces upward | the symbol stem above the third line faces downward | the
随机推荐
What is the principle of bone conduction earphones and who is suitable for bone conduction earphones
Quality means doing it right when no one is looking
JVM面试篇
C write TXT file
Pychart creates new projects & loads faster & fonts larger & changes appearance
If you want to rewind the video picture, what simple methods can you use?
[staff] pitch representation (treble clef | C3 60 ~ B3 71 pitch representation | C4 72 pitch representation | C5 84 pitch representation)
Leetcode question brushing (10) - sequential question brushing 46 to 50
批量检测url是否存在cdn—高准确率
大厂裁员潮不断,双非本科出身的我却逆风翻盘挺进阿里
Connected block template and variants (4 questions in total)
研发中台拆分过程的一些心得总结
How to run oddish successfully from 0?
【带你学c带你飞】1day 第2章 (练习2.2 求华氏温度 100°F 对应的摄氏温度
[untitled]
LeetCode刷题(十)——顺序刷题46至50
The video number will not be allowed to be put on the shelves of "0 yuan goods" in the live broadcasting room?
QT implementation interface jump
[staff] the direction of the symbol stem and the connecting line (the symbol stem faces | the symbol stem below the third line faces upward | the symbol stem above the third line faces downward | the
C return multiple values getter setter queries the database and adds the list return value to the window