当前位置:网站首页>自定义组件的 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>边栏推荐
- Mongodb non relational database
- flutter 中间一个元素,最右边一个元素
- Leetcode face T10 (1-9) array, ByteDance interview sharing
- PHP notes - use Smarty to set public pages (include, if, else, variable settings)
- C return multiple values getter setter queries the database and adds the list return value to the window
- Sword finger offer 42 Maximum sum of continuous subarrays
- Infix expression to suffix expression (computer) code
- STM32__ 05 - PWM controlled DC motor
- A quick understanding of digital electricity
- Websocket + spingboot realize code scanning login
猜你喜欢

After marriage

Addition without addition, subtraction, multiplication and division (simple difficulty)

【带你学c带你飞】4day第2章 用C语言编写程序(练习 2.5 生成乘方表与阶乘表

Systemserver service and servicemanager service analysis

Webgpu (I): basic concepts

Missing numbers from 0 to n-1 (simple difficulty)

CSDN article underlined, font color changed, picture centered, 1 second to understand

AcWing 245. Can you answer these questions (line segment tree)

Coordinatorlayout + tablayout + viewpager2 (there is another recyclerview nested inside), and the sliding conflict of recyclerview is solved

Additional: information desensitization;
随机推荐
附加:信息脱敏;
Mathematics in Sinorgchem: computational geometry
2022 low voltage electrician test question simulation test question bank simulation test platform operation
JS slow animation
After marriage
Provincial election + noi Part IV graph theory
Questions d'entrevue
[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 are the characteristics of common web proxy IP
CoordinatorLayout + TabLayout + ViewPager2(里面再嵌套一个RecyclerView),RecyclerView的滑动冲突解决
Email picture attachment
2022低压电工考试题模拟考试题库模拟考试平台操作
query词权重, 搜索词权重计算
【读书笔记】程序员修炼手册—实战式学习最有效(项目驱动)
Comparative analysis of MVC, MVP and MVVM, source code analysis
Es interview questions
[learn C and fly] 2day Chapter 8 pointer (practice 8.1 password unlocking)
Mongodb non relational database
[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)
【liuyubobobo-玩转Leetcode算法面试】【00】课程概述