美文网首页
vue中的父子组件调用

vue中的父子组件调用

作者: 长是人千离 | 来源:发表于2017-08-14 11:44 被阅读0次

1.把子组件的数据传给父组件

App.vue 父组件  Hello.vue 子组件  $emit

import hello from './components/Hello'

export default {

  name: 'app',

  'components': {

    hello

  },

  methods: {

    parentLisen(evtValue) {

      alert(evtValue) //evtValue 是子组件传过来的值

   }

 }

}

export default {

  name: 'hello',

  'methods': {

    chilCall(pars) {

       this.$emit('newNodeEvent', '我是子元素传过来的')

    }

  }

}

2.父组件的数据传给子组件

App.vue 父组件  Hello.vue 子组件  props

<template>

  <hello :options="message"></hello>  //父组件的数据传给子组件

</template>

import hello from './components/Hello'

export default {

  name: 'app',

  'components': {

    hello

  },

 data() {

    return {

      message: '123'

   }

 }

}

<template>

  <div>{{options}}</div>

</template>

export default {

   name: 'hello',

   props: ['options'],  //props传递

  }

相关文章

网友评论

      本文标题:vue中的父子组件调用

      本文链接:https://www.haomeiwen.com/subject/pbxurxtx.html