当前位置:网站首页>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>
在控制台测试如下:
边栏推荐
- After changing the password in MySQL under win10, the problem of sudden login failure is solved
- The combobox of easyUI selects the first option by default
- Just one dependency to give swagger a new skin, which is simple and cool~
- Excel VBA quick start (XII. Common usage of like comparison)
- 自己学习Cesium的笔记简介
- JS 延迟执行window.onload
- Understanding and practice of the trend of Bank of London foreign exchange
- 08.02 邻接表
- easyui datagrid 获取多条选中的数据进行操作
- Chapter 15 MySQL user management
猜你喜欢

day07-

OPPO 自研大规模知识图谱及其在数智工程中的应用

SQL injection less26 (filter spaces and comments, and use error injection without spaces)

知识库工具 | 微网站、文档中心、形象展示页拖拽即可生成(附模板,直接用)

Unity operates on Explorer, opens explorer, selects files, and filters files

Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering

08.02 adjacency table

yolov1

09.01 深度优先搜索

Qt中为工程添加资源文件、给按钮添加图片
随机推荐
Redis distributed lock + Lua atomic operation
SQL注入 Less24(二次注入)
Matlab draw short-term energy diagram
: could not determine a constructor for the tag ! RootAdmin
Jd.com won the highest award for intelligent science and technology in China! Inventory JD system intelligent technology
判断numpy array数组的维数
Protobuf之proto基础语法
Unity对资源管理器操作 打开资源管理器选择文件并筛选文件
What is Base64?
VB.net Chart1的处理
JMeter custom log and log analysis
Does Guosen Securities charge for opening a mobile account? Is it safe to open an account?
yolov1
matlab 画短时平均幅度谱
Go -- go language naming specification
[horizon sunrise X3 sect trial experience] + unpacking post
Afnetworking understand
Go----Go语言中的变量使用方法
Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
07 df 命令