Materi :

Source code latihan009.html :

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Latihan Vue 009</title>
    <link rel="stylesheet" href="bootstrap.min.css">
</head>
<body>
    <div id="app">
        <div class="jumbotron text-center">
            <h1>Bootstrap 4</h1>
            <p>Latihan009 - Komunikasi Komponen Pada Vue.js</p>
          </div>
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <pesan-alert 
                        jenis-alert="success"
                        pesan="Selamat datang di vue.js"
                        @kliksilang="munculkanPopup"
                    ></pesan-alert>
                </div>
                <div class="col-md-6">
                    <pesan-alert 
                        jenis-alert="warning" 
                        pesan="Belajar vue.js menyenangkan"
                        @kliksilang="munculkanPopup" 
                    ></pesan-alert>
                </div>
            </div>
        </div>
    </div>
    <script src="vue.js"></script>
    <script src="latihan009.js"></script>
</body>
</html>

Source code latihan009.js :

Vue.component('PesanAlert', {
    props: ['jenisAlert', 'pesan'],
    template: `
        <div :class="classAlert">
            <button type="button" class="close" @click="$emit('kliksilang', pesan)">×</button>
            {{ pesan }}
        </div>
    `,
    computed: {
        classAlert() {
            return 'alert ' + 'alert-' + this.jenisAlert + ' alert-dismissible';
        }
    }
});

new Vue ({    
    el: '#app',
    methods: {
        munculkanPopup(pesan) {
            alert('Popup dari ' + pesan)
        }
    }
});