【发布时间】:2019-03-11 07:51:04
【问题描述】:
我真的是 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>
// ChildOne.vue, basically the same for two and three aswell
<template>
<div id="child-one" v-blur="blurConfig" @click="$emit('toggle-blur')"></div>
</template>
<script>
export default {
name: 'ChildOne',
methods: {
toggleBlur () {
this.blurConfig.isBlurred = !this.blurConfig.isBlurred;
}
},
data () {
return {
blurConfig: {
isBlurred: false,
opacity: 0.3,
filter: 'blur(1.2px)',
transition: 'all .3s linear'
}
}
}
}
</script>
【问题讨论】:
-
你能提供更多代码吗?
-
@boussadjrabrahim 添加了代码示例!