当前位置:网站首页>自定义组件的 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>
边栏推荐
- STM32__05—PWM控制直流电机
- Mathematics in Sinorgchem: computational geometry
- how to add one row in the dataframe?
- The basic steps of using information theory to deal with scientific problems are
- STM32__ 05 - PWM controlled DC motor
- Face++ realizes face detection in the way of flow
- Set status bar color
- Bash bounce shell encoding
- Flutter un élément au milieu, l'élément le plus à droite
- Sword finger offer II 031 Least recently used cache
猜你喜欢
Types of exhibition items available in the multimedia interactive exhibition hall
About DNS
Build a modern data architecture on the cloud with Amazon AppFlow, Amazon lake formation and Amazon redshift
【OpenCV】-5种图像滤波的综合示例
Cesium dynamic diffusion point effect
2022-2028 global military computer industry research and trend analysis report
[learn C and fly] 2day Chapter 8 pointer (practice 8.1 password unlocking)
[reading notes] programmer training manual - practical learning is the most effective (project driven)
大厂裁员潮不断,双非本科出身的我却逆风翻盘挺进阿里
Ten minutes will take you in-depth understanding of multithreading - multithreaded teamwork: synchronous control
随机推荐
MongoDB非關系型數據庫
Soul app released the annual report on generation Z behavior: nearly 20% of young people love shopping in the vegetable market
Which kind of sports headphones is easier to use? The most recommended sports headphones
Connected block template and variants (4 questions in total)
Kibana操控ES
SQL server calculates the daily average and annual average of the whole province
C # use system data. The split mixed mode assembly is generated for the "v2.0.50727" version of the runtime, and it cannot be loaded in the 4.0 runtime without configuring other information
Jvm-01 (phased learning)
批量检测url是否存在cdn—高准确率
Sword finger offer 29 Print matrix clockwise
结婚后
Which brand of sports headset is better? Bluetooth headset suitable for sports
es面试题
Flutter un élément au milieu, l'élément le plus à droite
What are the characteristics of common web proxy IP
Divorce for 3 years to discover the undivided joint property, or
Yyds dry goods inventory accelerating vacuum in PG
Batch detect whether there is CDN in URL - high accuracy
Duplicate keys detected: ‘0‘. This may cause an update error. found in
trading