v-on: = @
父子界面传值
父组件给子组件
<template>
<childrenComponent :name="123">
<template>
export default {
name: "",
props: {
name: {
type: String
}
},
}
子组件给父组件
this.$emit('toP','msg')
<template>
<childrenComponent @toP="toP">
<template/>
export default {
methods: {
toP(e){
console.log('从子组件传过来的值',e)
}
}
}
直接使用ref拿值
export default {
methods: {
clickEvent(e){
console.log(this.$parent.msg1)
}
}
}
export default {
data(){
return{
msg:"data1"
}
},
methods:{
func(){
console.log("父界面触发子界面方法",this.msg)
}
}
}
<template>
<childrenComponent ref="cC"/>
</template>
export default {
methods:{
clickEvent(){
console.log(this.$refs.cC.msg)
console.log(this.$refs.cC.func)
}
}
}