本示例需要用到Vue.js[具体的可以访问官网,替换]
子类获取父类的变量的值
<coml v-bind:parent-Msg='msg'></coml>
//----------
//在子类中使用
props:['parentMsg']
//可以在子组件中使用
子类获取父类的方法
<coml @func='getDataMsgFormat'></coml>
//getDataMsgFormat 是父类的函数方法
//------
在子类触发的方法中嗲用
this.$emit('func')
综合实例
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">