add useRouter
This commit is contained in:
parent
088430e2fb
commit
52dc4c0128
|
@ -12,7 +12,11 @@
|
|||
</div>
|
||||
<div>
|
||||
<label for="description">Description</label>
|
||||
<textarea rows="5" id="description" v-model="enteredDescription"></textarea>
|
||||
<textarea
|
||||
rows="5"
|
||||
id="description"
|
||||
v-model="enteredDescription"
|
||||
></textarea>
|
||||
</div>
|
||||
<button>Add Product</button>
|
||||
</form>
|
||||
|
@ -21,9 +25,11 @@
|
|||
|
||||
<script>
|
||||
import { ref, inject } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
const router = useRouter();
|
||||
const addProduct = inject('addProduct');
|
||||
|
||||
const enteredTitle = ref('');
|
||||
|
@ -34,17 +40,18 @@ export default {
|
|||
addProduct({
|
||||
title: enteredTitle,
|
||||
description: enteredDescription,
|
||||
price: enteredPrice,
|
||||
price: enteredPrice
|
||||
});
|
||||
router.push('/products');
|
||||
}
|
||||
|
||||
return {
|
||||
enteredTitle,
|
||||
enteredPrice,
|
||||
enteredDescription,
|
||||
submitForm,
|
||||
submitForm
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
Reference in New Issue