【问题标题】:Calling parent method from child component not working in vue从子组件调用父方法在vue中不起作用
【发布时间】:2021-02-03 15:39:17
【问题描述】:

我正在尝试使用 $emit 从子组件调用父方法,但它没有调用该方法。请帮我找出哪里出错了。

父组件

<template>
 <Index></Index>
</template>

<script>
 import Index from 'views/index.vue'
 export default {
  components: {
   Index
  },
  methods: {
   reloading: function() {
    console.log("Hello");
   }
  }
 }
</script>

子组件

<template>
 <div>
   <v-btn @click="toggleChange">Change</v-btn>
 </div>
<template>

<script>
 export default {
  methods: {
   toggleChange: function() {
    var that = this;
    this.$axios.put('status.json')
    .then(response => {
      this.$emit('reloading');
     });
   },
  }
 }
</script>

【问题讨论】:

    标签: javascript vue.js parent-child


    【解决方案1】:

    你需要在你的父组件中监听事件并然后在它触发时调用函数:

    <Index @reloading="reloading"></Index>
    

    【讨论】:

      猜你喜欢
      • 2018-05-27
      • 2017-12-15
      • 1970-01-01
      • 2020-05-06
      • 2021-09-24
      • 2019-09-21
      • 1970-01-01
      • 2021-08-02
      • 2018-07-20
      相关资源
      最近更新 更多