父组件传值给子组件
父组件
father.vue
<template>
<div class="sidebar_contianer">
<sidebar-item :routerData="transmitData"></sidebar-item>
</div>
</template>
<script>
import sidebarItem from './sidebarItem'
export default {
data(){
return{
transmitData:"传给子组件的值"
}
},
components:{
sidebarItem
}
}
</script>
child.vue
子组件
<template>
<el-button type="primary" @click="queryAuthorization" size="small">点击</el-button>
</template>
<script>
export default {
name:'sidebarItem',
methods:{
queryAuthorization(){
alert(this.routerData);
}
},
props:{
routerData:{
type:"",
default:null
}
}
}
</script>
来源:oschina
链接:https://my.oschina.net/u/4236225/blog/4753004