Non-.vue single file component communication problem

without using the .vue single file,
I want to click the button in the profile component to make the modal box component display, mainly to modify the showmode value of the root instance.
started to want to use prop, and found that I didn"t find a suitable column in this situation.
use the event emitter. I don"t know how to use it.

the main structure of html is as follows

<div id="app">
    ...
    <router-view></router-view>
    <!-- use the modal component, pass in the prop -->
    <modal v-if="showModal" @close="showModal = false">
    <!--
        you can use custom content here to overwrite
        default content
    -->
    <h3 slot="header">custom header</h3>
    </modal>
</div>
<script type="text/x-template" id="profile">
    <button @click="togleModal"></button>
</script>
<script type="text/x-template" id="modal-template">
<transition name="modal">
    <div class="modal-mask">
    <div class="modal-wrapper">
        <div class="modal-container">
        <div class="modal-footer">
            <button class="modal-default-button" @click="$emit("close")">
                OK
            </button>
        </div>
        </div>
    </div>
    </div>
</transition>
</script>

js is as follows, streamlined

    var bus = new Vue();
    // register modal component
    Vue.component("modal", {
        template: "-sharpmodal-template"
    });
    var profile = {
        template: "-sharpprofile",
        data: function(){
            return {
            };
        },
        created: function () {
            bus.$on("show-modal", function(flag){  //
                //todo something
                console.log(flag);
            });
        },
        methods: {
        }
    };

    var routes = [
        {path: "/"},
        {path: "/profile", component: profile}
    ];
    var ROUTER = new VueRouter({
        routes: routes
    });
    var App = new Vue({
        el: "-sharpapp",
        data: {
            showModal: false,
            uinfo: {}
        },
        created: function () {
            bus.$emit("show-modal", this.showModal);
        },
        methods: {
            goProfile: function(){
                this.$router.history.push("/profile");
            }
        },
        watch: {
            "$route": function(to, from) {
               console.log(this.$route.path);
            }
        },
        router: ROUTER,
    });

do you really just need components to communicate? Take Chestnut
http://jsfiddle.net/631807682.


OK, the logic was not sorted out before, and a long event was spent on the event center. ide/migration.html-sharpdispatch-%E5%92%8C-broadcast-%E6%9B%BF%E6%8D%A2" rel=" nofollow noreferrer "> reference document
the modal box is an official example of copying, that is, the button that clicks to open the modal box is put in the component under vue-router. Click the button in the
component to distribute the event through $emit , and the
root instance receives the event through $on . Changing the showmodule value to the true, modal box displays

.

changed js

var bus = new Vue();
// register modal component
Vue.component('modal', {
    template: '-sharpmodal-template'
});
var profile = {
    template: '-sharpprofile',
    data: function(){
        return {
        };
    },
    created: function () {
    },
    methods: {
        /******************/
        togleModal: function(){
            bus.$emit('shmodal'); // 
        }
        /******************/
    }
};

var routes = [
    {path: '/'},
    {path: '/profile', component: profile}
];
var ROUTER = new VueRouter({
    routes: routes
});
var App = new Vue({
    el: '-sharpapp',
    data: {
        showModal: false,
        uinfo: {}
    },
    created: function () {
        var _this = this;
        /******************/
        // 
        bus.$on('shmodal', function(){
            _this.showModal = true;
        });
        /******************/
    },
    methods: {
        goProfile: function(){
            this.$router.history.push('/profile');
        }
    },
    watch: {
        '$route': function(to, from) {
           console.log(this.$route.path);
        }
    },
    router: ROUTER,
});
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e11f-2c3cc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e11f-2c3cc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?