1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
const app = Vue.createApp({
data(){
return{
showAlert: false,
alertText: "父元件的標題名稱"
}
},
methods:{
openAlert(){
this.showAlert = true;
},
closeAlert(){
this.showAlert = false;
}
}
})
app.component('alert-component',{
props:["title"],
methods:{
emitAlert(){
this.$emit("emit-alert")
}
},
template:`
<div class="alert alert-primary">{{ title }}
<button type="button" class="close" @click="emitAlert">×</button>
</div>
`
})
app.mount("#app");
|