当前位置:网站首页>Analysis of the principle of V-model and its application in user defined components
Analysis of the principle of V-model and its application in user defined components
2022-06-13 04:42:00 【Dax1_】
v-model Two-way binding of
v-model
yes v-bind
and v-on
Grammar sugar used together
<input v-model="value" />
// Is equivalent to :
<input :value="value" @input="value= $event.target.value" />
v-model Use in custom components
In order for our components to support v-model
Two way binding , The component needs to accept a props
And send out a input
event .
// Parent component
<template>
<div>
<Dialog :visible="x" @update:visible="x = $event"></Dialog>
<!-- Equivalent to -->
<Dialog v-model:visible="x"></Dialog>
</div>
</template>
// Child components Dialog
<script lang="ts">
export default {
props: {
visible: {
type: Boolean,
default: false
}
},
setup(props, context) {
const close = () => {
context.emit('update:visible', true)
}
return {
close}
}
};
</script>
Use... In custom components v-model
, take visible
Pass the value of to the subcomponent , Subcomponent receive prop(visible)
, meanwhile , Using update:visivle
event ( In general use input event , This is a personal habit ) Will be worth passing $emit
, Pass the value back to the parent component , Directly assign to visible
, This forms a two-way data binding for custom components .
边栏推荐
- Small program input element moving up
- Clear timer failure
- 【JS解决】leedcode 200. 岛屿数量
- Normal distribution (Gaussian distribution)
- 【JS解决】leedcode 117. 填充每个节点的下一个右侧节点指针 II
- General communication protocol for industrial Internet
- Blockly learning ----1 Work area, block, toolbox
- 正态分布(高斯分布)
- Cesium:CesiumLab制作影像切片与切片加载
- Latex operation
猜你喜欢
[try to hack] upload labs (temporarily write to 12)
【JS解决】leedcode 117. 填充每个节点的下一个右侧节点指针 II
CreateAnonymousThreadX给匿名线程传递参数
Createanonymousthreadx passes parameters to anonymous threads
2022 ICLR | CONTRASTIVE LEARNING OF IMAGE- AND STRUCTURE BASED REPRESENTATIONS IN DRUG DISCOVERY
一款開源的Markdown轉富文本編輯器的實現原理剖析
[JS solution] leedcode 117 Populate the next right node pointer II for each node
Redis主从复制、哨兵模式、集群
Ctfshow SQL injection (231-253)
Crawler scrapy framework learning 1
随机推荐
小程序基础入门(黑马学习笔记)
【Flutter 问题系列第 67 篇】在 Flutter 中使用 Get 插件在 Dialog 弹窗中不能二次跳转路由问题的解决方案
Suffix Automaton
Small program input element moving up
Uni app Ali font icon does not display
Colab使用教程(超级详细版)及Colab Pro/Pro+评测
General communication protocol for industrial Internet
前几年的互联网人vs现在的互联网人
How to use redis
SEO specification
Small program imitating Taobao Jiugong grid sliding effect
Ionic Cordova command line
ACM ICPC
NodeJS 解析 GET 请求 url 字符串
[LeetCode]-二分查找
JS, how to add grid style
一款开源的Markdown转富文本编辑器的实现原理剖析
Createanonymousthreadx passes parameters to anonymous threads
利用Javeswingjdbc基于mvc设计系统
2022年建筑架子工(建筑特殊工种)特种作业证考试题库及在线模拟考试