Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VueJS上仅使用Javascript将数据从子级传递到父级_Javascript_Vue.js - Fatal编程技术网

在VueJS上仅使用Javascript将数据从子级传递到父级

在VueJS上仅使用Javascript将数据从子级传递到父级,javascript,vue.js,Javascript,Vue.js,我知道在VueJS上使用$emit将数据从子组件传递到父组件,但我希望在javascript函数中获得该值。我的设想是: 家长 created () { this.$on('getValue', function (params) { console.log('PARAMS: ' + params) }) }, 儿童 methods: { checkBoxChanged (index) { this.$emit('getValue', 'some

我知道在VueJS上使用
$emit
将数据从子组件传递到父组件,但我希望在javascript函数中获得该值。我的设想是:

家长

 created () {
    this.$on('getValue', function (params) {
      console.log('PARAMS: ' + params)
    })
  },
儿童

methods: {
checkBoxChanged (index) {
      this.$emit('getValue', 'some value')
    },
}
但它不起作用。使用html,我可以在父对象上设置如下内容:(我有理由不能这样做!)


{{message}}

但我只需要使用javascript就可以做到这一点。

这就是如何将数据从子级传递到父级:

Vue.component('child-component'{
模板:
`
单击以将事件发射到父组件
`,
方法:{
单击(){
这是。$emit('buttonClicked','Magic from child component!');
},
},
});
Vue.component('父组件'{
模板:
`
子数据为:{{childData}}
`,
数据(){
返回{
childData:'空',
};
},
方法:{
handleClick(数据){
this.childData=数据;
},
},
});
新Vue({
el:“#应用程序”,
});

<template>
  <div>
    <h1>{{ message }}</h1>
    <child v-on:listenerChild="listenerChild"/>
  </div>
</template>