Vue子父组件之间数据传递方式
来源:互联网 发布:python 微信 编辑:程序博客网 时间:2024/06/11 13:05
Vue子父组件之间数据传递方式
子组件向父组件
在子组件通过 this.$emit(“事件名称”,传递的数据1,数据2,…);
<template> <div class="sonToFather"> <input placeholder="please input" v-model="sendDatas"/> <button v-on:click="sendData">Send</button> </div></template><script>export default { name: 'sonToFather', data:function(){ return { sendDatas:"", } }, methods: { sendData:function(e){ this.$emit("sonToFather",this.sendDatas);//通过emit传递 e.preventDefault(); } },}</script><style scoped></style>
然后在父组件中通过该子组件中 v-on:事件名=”接收方法” 来接收
<template> <div id="app"> <!-- 获得子组件传递过来的数据 --> <sonToFather v-on:sonToFather="getSonData"></sonToFather> </div></template><script>import SonToFather from './components/SonToFather'export default { name: 'app', components: { SonToFather }, methods:{ getSonData:function(text){ alert(text); }}</script><style></style>
父组件向子组件
父组件向子组件传递通过数据绑定的形式,在父组件中将要传递的数据绑定一下 v-text=”要传递的数据”
<template> <div id="app"> <!-- 父组件给子组件传递数据 --> <fatherToSon v-text="fatherToSonData"></fatherToSon> </div></template><script>import FatherToSon from './components/FatherToSon'export default { name: 'app', data:function(){ return{ fatherToSonData:"" } }, components: { FatherToSon }}</script><style></style>
然后在子组件中通过props的方式接收
<template> <div class="fatherToSon"> {{fatherToSonData}} </div></template><script>export default { name: 'FatherToSon', props:[ "fatherToSonData" ]}</script><style scoped></style>
阅读全文
0 0
- Vue子父组件之间数据传递方式
- Vue之父组件向子组件传递数据
- vue父组件向子组件传递多个数据
- 父组件向子组件传递数据(vue.js)
- 子组件传递数据到父组件(vue.js)
- vue 子组件向父组件传递数据
- Vue---组件之间的数据传递
- vue.js 组件之间传递数据
- vue.js 组件之间传递数据
- vue.js 组件之间传递数据
- vue 父子组件之间的数据传递
- Vue子父组件间的数据传递
- Vue.js组件—父组件与子组件之间的数据联系
- Vue--- 子 --> 父 组件传递参数
- Vue---父 --> 子 之间传递参数
- vue 兄弟组件之间传数据之通过父组件来传递
- vue.js中的子组件与父组件,prop传递数据
- 解决关于Vue父组件动态向子组件传递数据
- 【Scikit-Learn 中文文档】流形学习
- 博弈论(巴什博奕,威佐夫博弈,尼姆博弈,斐波那契博弈,sg函数)
- 属性动画的基本操作
- mysql索引长度
- PAT考试乙级1038(C语言实现)
- Vue子父组件之间数据传递方式
- 【C#基础】while循环和do-while循环
- 如何直接测试Spring Framework发送邮件的类
- 朋友们,我下班了...
- 【Scikit-Learn 中文文档】聚类
- The method of type must override a superclass method解决方式
- Oracle dblink报错:ORA-01017、ORA-02063解决
- strcopy
- jquery插件开发02