add useRouter

This commit is contained in:
Andreas Zweili 2021-09-06 12:57:45 +02:00
parent 088430e2fb
commit 52dc4c0128
1 changed files with 12 additions and 5 deletions

View File

@ -12,7 +12,11 @@
</div> </div>
<div> <div>
<label for="description">Description</label> <label for="description">Description</label>
<textarea rows="5" id="description" v-model="enteredDescription"></textarea> <textarea
rows="5"
id="description"
v-model="enteredDescription"
></textarea>
</div> </div>
<button>Add Product</button> <button>Add Product</button>
</form> </form>
@ -21,9 +25,11 @@
<script> <script>
import { ref, inject } from 'vue'; import { ref, inject } from 'vue';
import { useRouter } from 'vue-router';
export default { export default {
setup() { setup() {
const router = useRouter();
const addProduct = inject('addProduct'); const addProduct = inject('addProduct');
const enteredTitle = ref(''); const enteredTitle = ref('');
@ -34,17 +40,18 @@ export default {
addProduct({ addProduct({
title: enteredTitle, title: enteredTitle,
description: enteredDescription, description: enteredDescription,
price: enteredPrice, price: enteredPrice
}); });
router.push('/products');
} }
return { return {
enteredTitle, enteredTitle,
enteredPrice, enteredPrice,
enteredDescription, enteredDescription,
submitForm, submitForm
}; };
}, }
}; };
</script> </script>
@ -88,4 +95,4 @@ button:active {
background-color: #220031; background-color: #220031;
border-color: #220031; border-color: #220031;
} }
</style> </style>