vue 父组件给子组件传值及父组件触发子组件事件

news/2024/7/24 8:36:58

父组件

<template>
  <div>
    <!-- 顶部导航 -->
    <topNav
      title="XXX"
      @click="goBack"
      ref="child"
    ></topNav>
  </div>
 </template>
 <script>
import topNav from '../../components/topNavbar'
export default {
  components: { topNav },
  data() {
    return {
    }
  }
  methods: {
    goBack() {
      this.$refs.child.onClickLeft()
    }    
  }
}
</script>

子组件

<template>
  <div>
    <van-nav-bar
      :title="title"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    >
    </van-nav-bar>
  </div>
</template>
<script>
export default {
  name: 'topNav',
  props: {
    title: String
  },
  data() {
    return {

    }
  },
  methods: {
    onClickLeft() {
      console.log('我是子组件的方法')
      let that = this
      that.$router.go(-1)
    }
  }
}
</script>
<style lang="less" scoped>
</style>


http://www.niftyadmin.cn/n/1867334.html

相关文章

html3对标签,html标签3(转载)

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼练习h1{color : red ;}alert(我帅吗?)you are beautiful girl !!> you are beautiful girl ! Meta标签&#xff1a;Meta标签介绍&#xff1a;元素可提供有关页面的原信息(mata-information)&#xff0c;针对搜索引擎和更新频度…

推荐几个有关机器学习的微信公众号

个人观点&#xff0c;欢迎吐槽&#xff0c;欢迎推荐 机器学习研究会 特点&#xff1a;北京大学大数据与机器学习创新中心旗下的学生组织&#xff0c;时下最前沿咨询 数据挖掘入门与实战 特点&#xff1a;和其名字一样&#xff0c;入门的好帮手&#xff0c;实践的小能手 AI…

html锚点无法回顶部,不定高,好像使用锚点返回不了顶部啊

2-5、定位回到顶部* {margin: 0;padding: 0;}html,body {width: 100%;height: 100%;font-size: 14px;}header {height: 35px;background: #666;}header a {line-height: 35px;color: #fff;text-decoration: none;margin: 0 15px;}.container {height: 200%;}a[href"#top&q…

Markdown中代码段的标注显示特殊字符`如何输入?

在编辑 Markdown文件中&#xff0c;要输入代码段&#xff1a; 可用以下格式&#xff1a; [三个锐音符] [编辑语言的名称] [三个锐音符] 例如&#xff1a;从sklearn输出数据集 from sklearn import datasets 对于特殊字符【】名叫锐音符&#xff0c;很多人不知道怎么样输入?…

vue项目运行报错

先删除node,然后用cnpm i基本就能解决 npm install -g cnpm --registryhttps://registry.npm.taobao.org cnpm i

TypeError: Cannot read property ‘__ob__‘ of undefined

出现这个问题是因为.vue文件里面export default {}写了data(){} 却没写return{} export default {data(){} }

Python 图像读入处理(R+G+B+Gray)

# -*- coding: utf-8 -*- """ Created on Sat Jan 14 18:57:51 2017author: BruceLau1256 """import matplotlib.pyplot as plt # plt 用于显示图片 import matplotlib.image as mpimg # mpimg 用于读取图片 import numpy as npyuna mpimg.imre…

计算机在数学中的作用 论文,信息技术在小学数学教学中的作用论文范文.doc

信息技术在小学数学教学中的作用论文范文随着现代信息技术的迅速发展&#xff0c;人们运用信息技术的范围不断扩大&#xff0c;已逐渐成为人们生活中的一种必需品&#xff0c;对于人们的学习、生活及工作都有紧密的联系。20XX年我国教育部门明确提出要分三个层面推行信息技术教…