vue 父子组件通信
2018-06-06 15:16
267 查看
1.父子组建通信 for循环出来的数组传到子组件:组件功能是点击组件,字体扩大
阅读更多
//父组件 <div id="blog-posts-events-demo"> <div> <blog-post :style="{ fontSize: postFontSize + 'em' }" v-for="post in posts" v-bind:key="post.id" v-bind:post="post" @test="test" ></blog-post> </div> </div> //script new Vue({ el: '#blog-posts-events-demo', data: { posts:[ {id:2,title:'第一'}, {id:3,title:'第二'}, {id:4,title:'第三'} ], postFontSize:1 }, methods:{ test: function (data) { console.log(data); //子组件传递出来的$emit('事件','事件的参数值') console.log(this.postFontSize); return this.postFontSize += data } } })2.子组件通过props接收父组件传来的数值
Vue.component('blog-post', { props: ['post'], //从父组件传接收post template: '<div class="blog-post">' + '<h3>{{post.title}}</h3>' + '<button @click="enlargeText">扩大字体</button>'+ '<div v-html="post.content"></div>'+ '</div>', data: function () { }, methods:{ enlargeText: function () { this.$emit('test',0.1 ) //$emit输出事件传给父组件 } } });
阅读更多
相关文章推荐
- Vuejs——(10)组件——父子组件通信
- vue2.0父子组件以及非父子组件之间通信
- Vue全局组件开发,Vue.use(xxx)一次引入,全局使用 【Vue 非父子组件通信】
- vue2.0父子组件以及非父子组件通信
- Vue父子组件通信实践
- Vue2.0 父子组件之间通信
- vue.js学习笔记(三)--父子组件通信总结
- vue非父子组件之间的通信
- Vue父子组件之间通信
- vue2.0父子组件以及非父子组件如何通信
- vue学习笔记--父子组件通信
- Vue非父子组件通信详解
- vue开发:vue父子组件与非父子组件之间的通信
- vue父子组件通信
- vue2.0父子组件通信(慕课网)
- Vuejs第十篇之vuejs父子组件通信
- vue2.0父子组件以及非父子组件如何通信
- vue组件父子间通信之综合练习(聊天室)
- vue.js父子组件通信动态绑定
- 总结:Vue.js中父子组件之间的通信问题