This repository has been archived on 2021-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
vuejs_course/2021-03-27_routing-01-start.../src/components/users/UsersList.vue

56 lines
957 B
Vue

<template>
<button @click="confirmInput">Confirm</button>
<button @click="saveChanges">Save Changes</button>
<ul>
<user-item
v-for="user in users"
:key="user.id"
:name="user.fullName"
:role="user.role"
></user-item>
</ul>
</template>
<script>
import UserItem from './UserItem.vue';
export default {
components: {
UserItem
},
inject: ['users'],
data() {
return {
changesSaved: false
};
},
methods: {
confirmInput() {
this.$router.push('/teams');
},
saveChanges() {
this.changesSaved = true;
}
},
beforeRouteLeave(to, from, next) {
if (this.changesSaved) {
next();
} else {
const userWantsToLeave = confirm(
'Changes might be lost, do you want to continue?'
);
next(userWantsToLeave);
}
}
};
</script>
<style scoped>
ul {
list-style: none;
margin: 2rem auto;
max-width: 20rem;
padding: 0;
}
</style>