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 ...
随机推荐
- Codeforces Round #354 (Div. 2)-C. Vasya and String,区间dp问题,好几次cf都有这种题,看来的好好学学;
C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard ...
- msp430入门学习13
msp430的定时器--Timer_B(定时器B)
- HDU 5950 Recursive sequence 递推转矩阵
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- [bzoj1895][Pku3580]supermemo_非旋转Treap
supermemo bzoj-1895 Pku-3580 题目大意:给定一个n个数的序列,需支持:区间加,区间翻转,区间平移,单点插入,单点删除,查询区间最小值. 注释:$1\le n\le 6.1\ ...
- Maximum Product Subarray(最大连续乘积子序列)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- Linux下搭建maven私服Nexus 3.2.1-01
1. 私服介绍私服是指私有服务器,是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构建.有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库:否则, ...
- fuse-dfs挂载hdfs实录
部署安装了最新稳定版hadoop2.2.0.然后在网上找来fuse-dfs编译教程.可是最后失败了.至今原因未知--,错误描写叙述为:Transport endpoint is not connect ...
- Hadoop 知识
Map Reduce & YARN 简介 Apache Hadoop 是一个开源软件框架,可安装在一个商用机器集群中,使机器可彼此通信并协同工作,以高度分布式的方式共同存储和处理大量数据.最初 ...
- hdu 1711 KMP算法模板题
题意:给你两个串,问你第二个串是从第一个串的什么位置開始全然匹配的? kmp裸题,复杂度O(n+m). 当一个字符串以0为起始下标时.next[i]能够描写叙述为"不为自身的最大首尾反复子串 ...
- ios跟踪工具introspy使用
1.cydia安装introspy,前提要安装Applist (雷锋源) 2.设置中有introspy-Apps instrospy-Settings选项. 可以选择需要跟踪的app以及跟踪内 ...