2
<template>
<div>
<span class="badge" :class="styleStatus" > {{tipoStatus}}</span>
</div>
</template>
<script>
export default {
props:{
status:{
type:String
}
},
data: function () {
return {
tipoStatus: '',
styleStatus: '',
}
},
methods:{
alterarStatusAtivo() {
this.tipoStatus = 'Ativo'
this.styleStatus = 'badge-secondary'
},
alterarStatusInativo() {
this.tipoStatus = 'Inativo'
this.styleStatus = 'badge-danger'
}
},
watch:{
status(){
if (status == 'a'){
this.alterarStatusAtivo()
}
if(status == 'i'){
this.alterarStatusInativo()
}
}
}
}
My goal was every time the parent variable inherited by the props method was changed I did something in the template. I read that the watch method it keeps following the variable for each change of it. however unsuccessful. Would you have any solution for this code? i needed every time the status change to trigger some function.
code of the "father":
<template>
<div id="app">
Digite o status:
<input type="text" v-model="status" >
<showStatus :status="this.status"/>
</div>
</template>
<script>
import showStatus from "./components/show-status-ativo-inativo.vue"
export default {
name: "app",
components: { showStatus },
data(){
return{
status: ''
}
}
}
</script>