我对 Vue 非常陌生,似乎无法了解如何将事件从一个组件传递到其他组件。我目前正在使用v-blur,我想模糊除单击的组件之外的每个组件。我认为,当单击原始组件时,通过将事件传递给其他组件,我可以获得想要的效果。任何帮助深表感谢!
// Parent.vue
<template>
<div id="Parent">
<child-one @toggle-blur="toggleChildBlur"/>
<child-two @toggle-blur="toggleChildBlur"/>
<child-three @toggle-blur="toggleChildBlur"/>
</div>
</template>
<script>
import ChildOne from './ChildOne'
import ChildTwo from './ChildTwo'
import ChildThree from './ChildThree'
export default {
name: 'Parent',
components: {
ChildOne, ChildTwo, ChildThree
},
methods: {
toggleChildBlur () {
// Blur every child except the clicked one?
}
},
data () {
return {}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
// ChildOne.vue, basically the same for two and three aswell
<template>
<div id="child-one" v-blur="blurConfig" @click="$emit('toggle-blur')"></div> …Run Code Online (Sandbox Code Playgroud)