当前位置:网站首页>v-model组件化编程应用
v-model组件化编程应用
2022-07-30 14:20:00 【shewlong】
使用v-model完全接管子组件的数据(单文件)
父组件
<template>
<children v-model="formData"/>
</template>
<script setup>
import children from './children.vue'
const formData = reactive({
object:{
name:'',
sex:''
}})
</script>
子组件
<template>
<input v-model="formData.name" placeholder="请输入姓名" @update:value="updateValue('name', $event)">
</input>
<input v-model="formData.sex" placeholder="请输入性别" @update:value="updateValue('sex', $event)">
</input>
<button @click="submit">
提交
</button>
</template>
<script setup>
// defineProps和 toRefs在全局进行引入
const props = defineProps({
formData: {
type: Object,
default: () => {
return {
};
},
},
});
const emit = defineEmits(['update:model-value']);
//将reactive的值转为普通对象使用
const {
formData } = toRefs(props);
//提交表单信息
const submit = ()=>{
}
//状态更新
const updateValue = (fieldName: string, value: any): void => {
emit('update:model-value', Object.assign(modelValue.value, {
[fieldName]: value }));
};
</script>
此时,在父组件中的 f o r m D a t a 对象是实时变化的,可以随时拿出来用,无需封装对象过来取值 此时,在父组件中的formData对象是实时变化的,可以随时拿出来用,无需封装对象过来取值 此时,在父组件中的formData对象是实时变化的,可以随时拿出来用,无需封装对象过来取值
边栏推荐
- Allure进阶-动态生成报告内容
- 跳槽前,把自己弄成卷王
- 00 testers of seasoning after nearly a year, whether to change careers or to learn the software testing students summarized the following heart advice
- Understand Chisel language. 28. Chisel advanced finite state machine (2) - Mealy state machine and comparison with Moore state machine
- sql server安装失败怎么办(sql server安装不了怎么办)
- JSON common annotations
- 新一代开源免费的终端工具,太酷了
- PyQt5快速开发与实战 9.1 使用PyInstaller打包项目生成exe文件
- Baijiahao cancels the function of posting documents on the interface: the weight of the plug-in chain is blocked
- 吃透Chisel语言.28.Chisel进阶之有限状态机(二)——Mealy状态机及与Moore状态机的对比
猜你喜欢

【回归预测-CNN预测】基于卷积神经网络CNN实现数据回归预测附matlab代码

深入浅出零钱兑换问题——背包问题的套壳

新一代开源免费的终端工具,太酷了

Conversion between pytorch and keras (the code takes LeNet-5 as an example)

国内数字藏品的乱象与未来

MongoDB启动报错 Process: 29784 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=14)

Baijiahao cancels the function of posting documents on the interface: the weight of the plug-in chain is blocked

Flink实时数仓完结

从实例来看DAO:权力分散的伟大尝试
![[Advanced ROS] Lecture 11 Robot co-simulation based on Gazebo and Rviz (motion control and sensors)](/img/65/7bd87794ebde510ecfd1b0e4bd4c94.png)
[Advanced ROS] Lecture 11 Robot co-simulation based on Gazebo and Rviz (motion control and sensors)
随机推荐
3年软件测试经验面试要求月薪22K,明显感觉他背了很多面试题...
MySQL客户端工具的使用与MySQL SQL语句
手把手教你写让人眼前一亮的软件测试简历,收不到面试邀请算我输
华为7年经验的软件测试总监,给所有想转行学软件测试的朋友几点建议
双碳目标下:农田温室气体排放模拟
A simple change for problem, knapsack problem sets of shell
Flask Framework - Flask-Mail Mail
JSON common annotations
Understand Chisel language. 28. Chisel advanced finite state machine (2) - Mealy state machine and comparison with Moore state machine
Eclipse connects to SQL server database "recommended collection"
Get the Google Advertising ID as a unique identifier
Flink实时数仓完结
开源工具推荐:高性能计算辅助工具MegPeak
Interface automation framework, lm-easytest beta version released, use it quickly~
2022年,目前大环境下还适合转行软件测试吗?
Redis6.0 source code learning (5) ziplist
ccs软件的使用(靠谱挣钱的app软件)
自动化办公|办公软件和亿图脑图MindMaster快捷键
ECCV 2022 | Towards Data Efficient Transformer Object Detectors
canal抓取数据