首页 > 其他分享 >Vue 父组件调子组件方法[不参数版]

Vue 父组件调子组件方法[不参数版]

时间:2022-11-15 09:33:24浏览次数:43  
标签:Vue methods default child 组件 调子 childEvent

  • 子组件

<template>
  <div>
    
  </div>
</template>
<script>
  export default {
    methods: {
      childEvent() {
        alert("我是子组件方法");
      }
    }
  };
</script>
  • 父组件

<template>
  <div>
    <child ref="child"/>
  </div>
</template>
<script>
  import child from './child';
  export default {
    components: {
      child
    },
    methods: {
      parentEvent() {
        this.$refs.child.childEvent();
      }
    }
  };
</script>

标签:Vue,methods,default,child,组件,调子,childEvent
From: https://www.cnblogs.com/IT-IOS-MAN/p/16891354.html

相关文章

  • Vuex 持久化数据更新(vuex-persistedstate)
    在Vuex的使用过程中,会面临数据持久化问题,如:用户数据、菜单数据、必要的信息数据等。遇到问题:改变数据后F5刷新页面,数据不改变使用方式exportdefault{mounted......
  • 面试官:vue2和vue3的区别有哪些?
    一、Vue3与Vue2区别详述1.生命周期对于生命周期来说,整体上变化不大,只是大部分生命周期钩子名称上+“on”,功能上是类似的。不过有一点需要注意,Vue3在组合式API(Comp......
  • 一份vue面试知识点梳理清单
    写过自定义指令吗原理是什么指令本质上是装饰器,是vue对HTML元素的扩展,给HTML元素增加自定义功能。vue编译DOM时,会找到指令对象,执行指令的相关方法。自定义指令......
  • 自定义组件
    创建自定义组件类似于页面,一个自定义组件由jsonwxmlwxssjs4个文件组成。要编写一个自定义组件,首先需要在json文件中进行自定义组件声明(将component字段设为true......
  • 自定义组件传参
    参数声明Component({//参数properties:{//这里定义了innerText属性,属性值可以在组件使用时指定innerText:{type:String,value:'def......
  • 自定义组件事件
    子组件<viewbindtap="onItemChildClick"data-item="item">{{item}}</view>Component({methods:{onItemChildClick(event){this.trigger......
  • Component name “home“ should always be multi-word.eslintvue/multi-word-compone
    原文链接:https://blog.csdn.net/m0_67676064/article/details/126861235vue刚创建完就报错Componentname“home“shouldalwaysbemulti-word.eslintvue/multi-word-c......
  • vue项目中eslint报“Missing space before function parentheses”的问题解决
    原文链接:https://blog.csdn.net/u011523953/article/details/1067718681、问题原因:使用eslint时,严格模式下,报错Missingspacebeforefunctionparentheses(函数括号前缺少......
  • vue中 封装axios 以便管理和使用
    1.npm或yarn 安装axios到项目中npminstallaxiosyarnaddaxios2.新建api文件引入服务器的基本IP:端口//所有用户的接口importaxiosfrom"axios";//服......
  • 1-3 k8s各组件介绍
    k8s各组件介绍master端:apiserver:资源操作的唯一入口,介绍用户的命令,提供认证,授权,api注册和发现等机制scheduler:负责集群资源调度,按照预定的调度策略将pod调度到相......