【发布时间】:2018-01-03 04:01:56
【问题描述】:
我在使用 VueJS 中的 $emit 设置唯一活动组件时遇到问题。
我想什么时候点击标签栏组件中的标签A,它会be active in Tab A, not active in Tab B和标签B一样。
希望你的家伙有所帮助。
父组件:
<template>
<div class="tab-a" v-if="taba = true">
<span>This is Tab A</span>
</div>
<div class="tab-b" v-if="tabb = true">
<span>This is Tab B and I want Tab A is not Active</span>
</div>
<tabbar @open="ToggleOpen"></tabbar>
</template>
<script>
ToggleOpen: function (obj) {
obj.current = true
obj.rest = false
},
</script>
标签栏组件:
<template>
<div class="photo_react">
<li @click="open({current: 'taba', rest: 'tabb'})" class="tab-a" data-tooltip="Open TabA">Open TabA</li>
<li @click="open({current: 'tabb', rest: 'taba'})" class="tab-b" data-tooltip="Open TabB">Open TabB</li>
</div>
</template>
<script>
export default {
methods: {
opencomment: function (obj) {
this.$emit('open', obj)
}
}
}
</script>
【问题讨论】:
-
在
v-if,看起来你只是使用变量赋值。那可能需要双等号。例如:v-if="taba == true".