当前位置:网站首页>自定义组件的 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>边栏推荐
- Questions d'entrevue
- [staff] pitch representation (treble clef | C3 60 ~ B3 71 pitch representation | C4 72 pitch representation | C5 84 pitch representation)
- Cesium dynamic diffusion point effect
- Remote connection to MySQL under windows and Linux system
- 结婚后
- STM32__05—PWM控制直流电机
- Software testing learning notes - network knowledge
- [learn C and fly] 4day Chapter 2 program in C language (exercise 2.5 generate power table and factorial table
- Pat a-1165 block reversing (25 points)
- Connected block template and variants (4 questions in total)
猜你喜欢

Mongodb base de données non relationnelle
Face++ realizes face detection in the way of flow

STM32__05—PWM控制直流电机

大厂裁员潮不断,双非本科出身的我却逆风翻盘挺进阿里

Webgpu (I): basic concepts

SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding
![[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

Feature query of hypergraph iserver rest Service

Leetcode question brushing (10) - sequential question brushing 46 to 50

【OpenCV】-5种图像滤波的综合示例
随机推荐
【无标题】
大厂裁员潮不断,双非本科出身的我却逆风翻盘挺进阿里
Formatting logic of SAP ui5 currency amount display
[pit] how to understand "parameter fishing"
[learn C and fly] day 5 chapter 2 program in C language (Exercise 2)
Special symbols in SAP ui5 data binding syntax, and detailed explanation of absolute binding and relative binding concepts
JVM面试篇
【带你学c带你飞】4day第2章 用C语言编写程序(练习 2.5 生成乘方表与阶乘表
Which kind of sports headphones is easier to use? The most recommended sports headphones
[untitled]
[learn C and fly] 1day Chapter 2 (exercise 2.2 find the temperature of Fahrenheit corresponding to 100 ° f)
Multi threaded query, double efficiency
Stack - es - official documents - filter search results
Analysis of FLV packaging format
2022安全员-C证考试题及模拟考试
实现一个自定义布局的扫码功能
Quality means doing it right when no one is looking
2022低压电工考试题模拟考试题库模拟考试平台操作
连通块模板及变式(共4题)
The number one malware in January 2022: lokibot returned to the list, and emotet returned to the top