0👍
How about using Vue mixins feature?
At App.vue
<script>
import ModalComponents from '@/ModalComponents'
export default {
mixins: [ModelComponents],
mounted(){
this.fetchUser()
}
}
</script>
- [Vuejs]-Strange behavior: the displaying of vue-multiselect options panel cause a button unclickable
0👍
App.Vue
<template>
<div>
<ModalComponents :emps="emp">
</div>
</template>
<script>
export default {
data() {
return {
emp: null,
}
}
methods: {
fetchUser() {
fetch('api/employee').then(res => res.json())
.then(res => {
this.emp = res.data;
})
}
}
}
</script>
ModalComponents
<template>
<div>
{{emps.name}}
</div>
</template>
<script>
export default {
props: [
'emps'
],
}
</script>
Otherway
App.vue
<template>
<div>
<ModalComponents v-on:fetch-user="getUser">
</div>
</template>
<script>
export default {
data() {
return {
emp: null,
}
},
methods: {
getUser(newEmp) {
this.emp = newEmp
}
}
}
</script>
ModalComponents
<template>
<div>
<form @submit.prevent="fetchUser">
...
</form>
</div>
</template>
<script>
export default {
methods: {
fetchUser() {
fetch('api/employee').then(res => res.json())
.then(res => {
this.emp = res.data;
})
const newEmp = this.emp
this.$emit('fetch-user', newEmp)
}
}
}
</script>
- [Vuejs]-How to redirect when the focus in input is false in Vuejs
- [Vuejs]-Can I create a component with a loop in vue js? Is there a way to make it recognized as html tags?
Source:stackexchange.com