iT邦幫忙

0

vue EventBus.$emit EventBus.$on 更改資料

我覺得我應該是有哪個盲點沒發現
task是想透過資訊傳遞讓:class綁定
希望大家能幫我找到盲點 謝謝
以下是顯示的畫面

<template>
    <div class="item1">
        <ul class="novice_left_nav tab_click fl">
            <div class="novice_top"></div>
            <li :class="{'hasSelece': SkillType == 'Baccarat'}">
                <a href="javascript:void(0);" @click="changeContent('webTutorialSkills');SkillType='Baccarat'"><i class="novice_icon_1"></i>百家乐</a>
            </li>
            <li :class="{'hasSelece': SkillType == 'Roulette'}">
                <a href="javascript:void(0);" @click="changeContent('roulette');SkillType='Roulette'"><i class="novice_icon_3"></i>轮盘</a>
            </li>
            <li :class="{'hasSelece': SkillType == 'Sicbo'}">
                <a href="javascript:void(0);" @click="changeContent('sicbo');SkillType='Sicbo'"><i class="novice_icon_4"></i>骰宝</a>
            </li>
            <li :class="{'hasSelece': SkillType == 'Other'}">
                <a href="javascript:void(0);" @click="changeContent('other');SkillType='Other'"><i class="novice_icon_5"></i>其他</a>
            </li>
        </ul>

        <router-view></router-view>

        <div class="clearfix"></div>
    </div>
</template>
<script>
import EventBus from 'scripts/common/EventBus';

export default {

    data() {
        return {
            SkillType: 'Baccarat',

            BettingTipsType: {
                Baccarat: 'Baccarat',
                Roulette: 'Roulette',
                Sicbo: 'Sicbo',
                Other: 'Other',
            },
        };
    },

    created() {
        EventBus.$on('changeClass', type => {
            this.SkillType = type;
            console.log(type);
            console.log(this.SkillType);
        });
    },

    methods: {
        changeContent(type) {
            this.$router.push({ name: type });
        }
    },
    
    // beforeDestroy() {
    //     EventBus.$off('changeClass');
    // }
};
</script>

console.log的結果有顯示出對應的值
以下是EventBus.$emit

ReturnBack: function () {
            console.log(this.$route.params.type);
            this.$router.push({ name: this.$route.params.type, params: { DetailBettingTipsType: this.$route.params.BettingTipsType } });
            EventBus.$emit('changeClass', this.DetailBettingTipsType);
        }

照理說this.SkillType修改後class應該就會綁定特定的dom
但卻沒有 class一直是綁在Baccarat百家樂這個dom
想請問是哪邊出了問題
謝謝

法蘭克 iT邦新手 5 級 ‧ 2017-12-28 11:42:11 檢舉
你好~
我嘗試幫你解決問題,但是發現你貼的程式有點怪怪的,你的需求是點了按鈕換頁,並把點擊的那個選項加上class是嗎?

1. 你可以用router-link去做處理,就不用使用到eventBus了
2. 繼續使用eventBus,但是你的寫法有點怪怪的,可能需要修改一下,離開頁面之前先進行eventBus.$emit( ) .

PS: 你最後貼的程式 ReturnBack 請問有這個語法嗎?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答