vue中sync,v-model----双向数据绑定
<sycn-son :foo="fatherFoo"></sycn-son>
props:{
foo: String
},
<button @click="updateFoo">点击改变</button>
methods:{
updateFoo(){
this.$emit('update','foo被子组件改变啦')
}
}
<sycn-son :foo="fatherFoo" v-on:update="sonFoo => fatherFoo = sonFoo"></sycn-son>
<sycn-son :foo.sync="fatherFoo"></sycn-son>
updateFoo(){
this.$emit('update:foo','foo被子组件改变啦')
}
<template>
<div>
<sycn-son :foo.sync="fatherFoo"></sycn-son>
<br>
父组件的foo:{{fatherFoo}}
<button @click="syncFatherUpdate">父组件来点击改变</button>
</div> </template> <script>
import sycnSon from './sycnSon'
export default {
name: 'sycnFather',
components:{
sycnSon
},
data () {
return {
fatherFoo:'我是一开始的foo'
}
},
methods:{
syncFatherUpdate (){
this.fatherFoo = '被父组件改变'
} }
}
</script>
<template>
<div>
子组件的foo:{{foo}}
<button @click="updateFoo">点击改变</button>
</div>
</template> <script>
export default {
name: 'sycnSon',
props:{
foo: String
}, methods:{
updateFoo(){
this.$emit('update:foo','foo被子组件改变啦')
}
}
}
</script>
JSON.parse(JSON.stringify(this.analysisData))
<template>
<div>
<model-son v-model="fatherMsg"></model-son>
<br>
父组件:{{fatherMsg}}
<button @click="modelFatherUpdate">父组件来点击改变</button> </div> </template> <script>
import modelSon from './modelSon'
export default {
name: 'modelFather',
components:{
modelSon
},
data () {
return {
fatherMsg:'父组件一开始定义的fatherMsg'
}
},
methods:{
modelFatherUpdate (){
this.fatherMsg = 'fatherMsg被父组件改变'
} }
}
</script>
子组件:
<template>
<div>
子组件的msg:
<input :value="value" @input="$emit('input', $event.target.value)">
</div> </template> <script>
export default {
name: 'modelSon',
// 必须是value
props:{
value:String
},
}
</script>
注意:注册必须是value
model: {
prop: 'msg',
event: 'change'
},
props:{
msg:String
},
<template>
<div>
<model-son v-model="fatherMsg"></model-son>
<br>
父组件:{{fatherMsg}}
<button @click="modelFatherUpdate">父组件来点击改变</button> </div> </template> <script>
import modelSon from './modelSon'
export default {
name: 'modelFather',
components:{
modelSon
},
data () {
return {
fatherMsg:'父组件一开始定义的fatherMsg'
}
},
methods:{
modelFatherUpdate (){
this.fatherMsg = 'fatherMsg被父组件改变'
} }
}
</script>
<template>
<div>
子组件的msg:{{msg}}
<button @click="modelUpdate">点击改变</button>
</div> </template> <script>
export default {
name: 'modelSon',
model: {
prop: 'msg',
event: 'change'
},
props:{
msg:String
},
methods:{
modelUpdate (){
this.$emit('change','msg被子组件改变了!')
} }
}
</script>
vue中sync,v-model----双向数据绑定的更多相关文章
- 怎样在 Vue 中使用 v-model 实现双向数据绑定?
1. 所谓 双向数据绑定, 可以理解为: 修改 A , B 会跟着被修改, 修改 B , A 会跟着被修改. 常用在需要 进行用户输入的地方, 比如 这些 html 标签: input.select ...
- Vue中.sync修饰符
Vue 中 sync的作用 <FatherComponent :a.sync = 'b'><FatherComponent /> 子组件中emit('update:a',... ...
- vue.js--基础 事件结合双向数据绑定实现todolist 待办事项 已经完成 和进行中,键盘事件
<template> <div id="app"> <h1>{{ msg }}</h1> <input type=" ...
- Vue指令之`v-model`和`双向数据绑定
v-bind 只能实现数据的单向绑定,从 M 自动绑定到 V, 无法实现数据的双向绑定 <input type="text" v-bind:value="msg& ...
- Vue学习笔记【7】——Vue指令之v-model和双向数据绑定
v-model是唯一可以实现双向数据绑定的vue指令 单向数据绑定:修改内存中的数据,页面上同步更改.v-bind <!-- v-bind 只能实现数据的单向绑定,从 M 自动绑定到 V, 无法 ...
- vue中v-model的数据双向绑定(重要)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- angular4.0中form表单双向数据绑定正确姿势
issue:用[(ngModel)]="property"指令双向数据绑定,报错. reason1:使用ngModel绑定数据需要注入FormsModule模块,在app.modu ...
- angular,vue,react的基本语法—双向数据绑定、条件渲染、列表渲染、angular小案例
基本语法: 1.双向数据绑定 vue 指令:v-model="msg" react constructor(){ this.state{ msg:"双向数据绑定" ...
- vue.js--基础 事件结合双向数据绑定实现todolist,增加和删除功能
原理很简单,写一个input框,定义一个空的list,当在input中增加数据时,就往list中添加数据,然后在循环这个list的数据,删除数据就是调用list中的splice <templat ...
随机推荐
- Python模块:logging、
logging模块: 很多程序都有记录日志的需求,并且日志中包含的信息既有正常的程序访问日志,还可能有错误.警告等信息输出.Python的logging模块提供了标准的日志接口,你可以通过它存储各种格 ...
- 仪仗队(bzoj 2190)
Description 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是 ...
- [JLOI2008]提示问题
题目描述 最近在JLOI网上的一个流行游戏中,选手要回答很难的问题.假如在规定时间内不能回答,系统将给出1个提示,之后再依次给出第2,3个提示.出现在答案中的是字母和下列字符: '.',',',':' ...
- 【BZOJ4474】isomorphism(树的同构,哈希)
题意:一个无向树的度数为 2的结点称为假结点,其它结点称为真结点.一个无向树的简化树其结点由原树的全体真结点组成,两个真结点之间有边当且仅当它们在原树中有边,或者在原树中有一条联结这两个结点的路,其中 ...
- linux 文件系统 磁盘分区 格式化
1.du -sh test #查看文件或者目录的大小 2.cat file | wc -l #查看文件的行数 3.ls dirname | wc -l #查看文件个数 4.stat install.l ...
- csu - 1536: Bit String Reordering (模拟)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1536 不知道为何怎么写都写不对. 这题可以模拟. 虽然题目保证一定可以从原串变成目标串,但是不一定 ...
- linux 下使用genymotion
在官网下载genymotion http://www.genymotion.cn/ 然后进行下面操作 1.假设本机没有virtualbox 下载一个 能够通过指令 sudo apt-get inst ...
- rsync 3.1.1源代码编译安装配置
http://rsync.samba.org/ rsync-3.1.1.tar.gz ---0.卸载rpm # yum remove rsync -----1.安装: tar -zxvf rsync- ...
- HDU4930-Fighting the Landlords
题意:斗地主,就是要自己出牌.使得对手在这一轮无法出牌,或者有出牌的可能.可是你的牌已经走完了.假设符合这些条件的话,输出Yes.否则输出No. 思路:先预处理能直接把牌走完的情况,假设不行的话就直接 ...
- ZOJ 1806 (小数高精度)
题意:八进制小数转化成十进制的小数. 0.d1d2d3 ... dk [8] = 0.D1D2D3 ... Dm [10] 例: 0.75 [8] = 7*8^-1+5*8^-2 = ( 5/8 + ...