当前位置:网站首页>v-model语法糖的实现
v-model语法糖的实现
2022-07-26 21:35:00 【废物的自我修养记录】
v-model语法糖的实现
1 定义子组件
<template>
<div>
<span>
<input
ref="input"
:value="value"
@input="$emit('input', $event.target.value)"
/>
</span>
</div>
</template>
<script>
export default {
props: {
value: {
type: String,
default: "",
},
},
};
</script>
2 在父组件中使用子组件
<template>
<div>
<!-- v-model语法糖的实现 -->
<my-input v-model="price" />
<!-- 不使用v-model -->
<my-input :value="price" @input="inputChange" />
<h2>{
{ price }}</h2>
</div>
</template>
<script>
import MyInput from "./components/MyInput.vue";
export default {
name: "Test0726",
components: {
MyInput,
},
data() {
return {
price: "",
};
},
methods: {
inputChange(e) {
this.price = e;
},
},
};
</script>
在控制台测试如下:
边栏推荐
- The potential of emerging markets is unlimited, and advance.ai risk control products help Chinese offshore enterprises build a solid foundation for safe development
- Xshell7 personal free download, use
- 想让照片中的云飘起来?视频编辑服务一键动效3步就能实现
- 【C语言基础】17 链表初探
- Pytorch--Visdom使用
- Circular progress bar animation based on cashapelayer and Bezier curve
- SQL injection less26 (filter spaces and comments, and use error injection without spaces)
- unity 获取网络时间
- 【Try to Hack】防火墙(一)
- win10下mysql改密码后,突然登录不上的问题解决过程记录
猜你喜欢
随机推荐
Difference between D and C
unity 安装失败:operation not permitted, mkdir......
yolov1
: could not determine a constructor for the tag !RootAdmin
[horizon sunrise X3 sect trial experience] + unpacking post
The combobox of easyUI selects the first option by default
进程的概念和分类
Afnetworking understand
Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
C data type_ From rookie tutorial
SQL注入 Less26(过滤空格和注释符,使用不带空格的报错注入)
Let me show you the MySQL isolation level. What happens when two transactions operate on the same row of data at the same time?
C# 数据类型_摘自菜鸟教程
EasyUI DataGrid obtains multiple selected data for operation
Redis 分布式锁 + Lua原子操作
JMeter自定义日志与日志分析
Let Xiaobai thoroughly understand performance tuning
Props with type Object/Array must...
学了那么久的用例设计,知不知道为什么设计测试用例
08.02 adjacency table








![[tool] apifox](/img/a8/73325ec02a8bed2db2a8168f5bd40e.png)
