学无先后,达者为师

网站首页 Vue 正文

vue 子页面调用父页面常用方式

作者:沉、睡 更新时间: 2022-02-02 Vue

vue 子页面调用父页面常用方式

父组件

<template>
  <div>
    <child @fatherMethod="fatherMethodOther"></child>
  </div>
</template>
<script>
  import child from './child';
  export default {
    components: {
      child
    },
    methods: {
      fatherMethodOther(str) {
        console.log(str);
      }
    }
  };
</script>

子组件

<template>
  <div>
    <button @click="childMethod">点击</button>
  </div>
</template>
<script>
  export default {
    methods: {
      childMethod() {
        this.$emit('fatherMethod', '传参');
      }
    }
  };
</script>

原文链接:https://blog.csdn.net/zz975896590/article/details/119991142

栏目分类
最近更新