vue父子组件传递信息
2017-06-26 16:56
459 查看
a.vue(父组件)
b.vue(子组件)
<template> <div id="app"> <!--<img src="./assets/logo.png">--> <router-view></router-view> {{str}} <ComponetA :sends="datas" :abcdef="da1" @parnet-child="parnetchilds"></ComponetA> :sends(向子组件发送相关信息的)
parnet-child子组件向父组件发送相关信息的
</div> </template> <script> import ComponetA from '../src/components/componetA.vue' export default { name: 'app', data(){ return { str:'', datas:[ { name:'网易', url:'163.com' }, { name:'腾讯', url:'qq.com' } ], da1:{ a:12, b:22 } } }, components:{ ComponetA }, methods:{ parnetchilds(str1){ this.str=str1 } } } </script> <style> #app { font-family: 'Avenir', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } </style>
b.vue(子组件)
<template> <div class="hello"> <h1>{{ msg }}</h1> <ul> <li v-for="item in sends"@click="btn2(item.name)"> {{item.name}} {{item.url}} </li> </ul> <ul> <li v-for="items in abcdef" @click="items1"> {{items}} </li> </ul> <button @click="btn1">点击</button> </div> </template> <script> export default { name: 'hello', data () { return { msg: '我是父组件' } }, props:{ //在父组件中定义的相关类型,数据之类的 sends:{ type:Array, default:'' }, abcdef:{ type:Object, default:'' } }, methods:{ btn1(){ alert(1) }, btn2(s){ //子向父发送请求 this.$emit('parnet-child',s) }, items1(){ alert('父传递给子的信息哦') } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> h1, h2 { font-weight: normal; } ul { list-style-type: none; padding: 0; } li { display: inline-block; margin: 0 10px; } a { color: #42b983; } </style>
相关文章推荐
- vue父子组件的数据传递示例
- vue学习记录——父子组件间传递数据
- 关于vue.js父子组件数据传递
- Vue 父子组件数据传递的四种方式( inheritAttrs + $attrs + $listeners)
- vue 父子组件属性传递
- Vue4种父子组件数据双向传递
- vue父子组件数据传递方式
- Vue4种父子组件数据双向传递
- 前端框架vue.js系列(7):父子组件参数变化传递规范
- VUE父子组件之间值传递
- Vue.js 父子组件相互传递数据
- vue 父子组件之间的数据传递
- react都这么无情了,vue还是那么有义,4种父子组件数据双向传递大法
- vue教程3-05 vue组件数据传递、父子组件数据获取,slot,router路由
- Vue 父子组件的数据传递、修改和更新方法
- vue父子组件的数据传递
- vue中父子组件的相互传递
- vue-cli中父子组件间的变量传递
- vue2.0父子组件间传递数据的方法
- vue组件间通信、数据传递(父子组件,同级组件)