38 changed files with 24580 additions and 7 deletions
@ -0,0 +1,4 @@ |
|||
> 1% |
|||
last 2 versions |
|||
not dead |
|||
not ie 11 |
@ -0,0 +1,17 @@ |
|||
module.exports = { |
|||
root: true, |
|||
env: { |
|||
node: true |
|||
}, |
|||
'extends': [ |
|||
'plugin:vue/vue3-essential', |
|||
'eslint:recommended' |
|||
], |
|||
parserOptions: { |
|||
parser: '@babel/eslint-parser' |
|||
}, |
|||
rules: { |
|||
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', |
|||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
.DS_Store |
|||
node_modules |
|||
/dist |
|||
|
|||
|
|||
# local env files |
|||
.env.local |
|||
.env.*.local |
|||
|
|||
# Log files |
|||
npm-debug.log* |
|||
yarn-debug.log* |
|||
yarn-error.log* |
|||
pnpm-debug.log* |
|||
|
|||
# Editor directories and files |
|||
.idea |
|||
.vscode |
|||
*.suo |
|||
*.ntvs* |
|||
*.njsproj |
|||
*.sln |
|||
*.sw? |
@ -0,0 +1,24 @@ |
|||
# docuko3apii |
|||
|
|||
## Project setup |
|||
``` |
|||
npm install |
|||
``` |
|||
|
|||
### Compiles and hot-reloads for development |
|||
``` |
|||
npm run serve |
|||
``` |
|||
|
|||
### Compiles and minifies for production |
|||
``` |
|||
npm run build |
|||
``` |
|||
|
|||
### Lints and fixes files |
|||
``` |
|||
npm run lint |
|||
``` |
|||
|
|||
### Customize configuration |
|||
See [Configuration Reference](https://cli.vuejs.org/config/). |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
presets: [ |
|||
'@vue/cli-plugin-babel/preset' |
|||
] |
|||
} |
@ -0,0 +1,19 @@ |
|||
{ |
|||
"compilerOptions": { |
|||
"target": "es5", |
|||
"module": "esnext", |
|||
"baseUrl": "./", |
|||
"moduleResolution": "node", |
|||
"paths": { |
|||
"@/*": [ |
|||
"src/*" |
|||
] |
|||
}, |
|||
"lib": [ |
|||
"esnext", |
|||
"dom", |
|||
"dom.iterable", |
|||
"scripthost" |
|||
] |
|||
} |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,27 @@ |
|||
{ |
|||
"name": "docuko3apii", |
|||
"version": "0.1.0", |
|||
"private": true, |
|||
"scripts": { |
|||
"serve": "vue-cli-service serve", |
|||
"build": "vue-cli-service build", |
|||
"lint": "vue-cli-service lint" |
|||
}, |
|||
"dependencies": { |
|||
"axios": "^1.9.0", |
|||
"bootstrap": "^5.3.6", |
|||
"core-js": "^3.8.3", |
|||
"vue": "^3.2.13", |
|||
"vue-router": "^4.0.3" |
|||
}, |
|||
"devDependencies": { |
|||
"@babel/core": "^7.12.16", |
|||
"@babel/eslint-parser": "^7.12.16", |
|||
"@vue/cli-plugin-babel": "~5.0.0", |
|||
"@vue/cli-plugin-eslint": "~5.0.0", |
|||
"@vue/cli-plugin-router": "~5.0.0", |
|||
"@vue/cli-service": "~5.0.0", |
|||
"eslint": "^7.32.0", |
|||
"eslint-plugin-vue": "^8.0.3" |
|||
} |
|||
} |
After Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,17 @@ |
|||
<!DOCTYPE html> |
|||
<html lang=""> |
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> |
|||
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> |
|||
<title><%= htmlWebpackPlugin.options.title %></title> |
|||
</head> |
|||
<body> |
|||
<noscript> |
|||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> |
|||
</noscript> |
|||
<div id="app"></div> |
|||
<!-- built files will be auto injected --> |
|||
</body> |
|||
</html> |
@ -0,0 +1,30 @@ |
|||
<template> |
|||
<nav> |
|||
<router-link to="/">Domů</router-link> | |
|||
<router-link to="/products">Produkty</router-link> |
|||
</nav> |
|||
<router-view/> |
|||
</template> |
|||
|
|||
<style> |
|||
#app { |
|||
font-family: Avenir, Helvetica, Arial, sans-serif; |
|||
-webkit-font-smoothing: antialiased; |
|||
-moz-osx-font-smoothing: grayscale; |
|||
text-align: center; |
|||
color: #2c3e50; |
|||
} |
|||
|
|||
nav { |
|||
padding: 30px; |
|||
} |
|||
|
|||
nav a { |
|||
font-weight: bold; |
|||
color: #2c3e50; |
|||
} |
|||
|
|||
nav a.router-link-exact-active { |
|||
color: #42b983; |
|||
} |
|||
</style> |
After Width: | Height: | Size: 6.7 KiB |
@ -0,0 +1,7 @@ |
|||
import { createApp } from 'vue' |
|||
import App from './App.vue' |
|||
import router from './router' |
|||
|
|||
import "bootstrap/dist/css/bootstrap.min.css" |
|||
//import "bootstrap/dist/js/bootstrap.bundle.js"
|
|||
createApp(App).use(router).mount('#app') |
@ -0,0 +1,30 @@ |
|||
import { createRouter, createWebHistory } from 'vue-router' |
|||
import HomeView from '../views/HomeView.vue' |
|||
import ProductsView from '../views/ProductsView.vue' |
|||
import ProductDetailView from '../views/ProductDetailView.vue'; |
|||
|
|||
const routes = [ |
|||
{ |
|||
path: '/', |
|||
name: 'Home', |
|||
component: HomeView |
|||
}, |
|||
{ |
|||
path: '/products', |
|||
name: 'Products', |
|||
component: ProductsView |
|||
}, |
|||
{ |
|||
path: '/products/:id', |
|||
name: 'ProductDetail', |
|||
component: ProductDetailView, |
|||
props: true, // to umožní :id -> prop komponentu
|
|||
} |
|||
] |
|||
|
|||
const router = createRouter({ |
|||
history: createWebHistory(process.env.BASE_URL), |
|||
routes |
|||
}) |
|||
|
|||
export default router |
@ -0,0 +1,14 @@ |
|||
<template> |
|||
<div class="home"> |
|||
<img alt="Vue logo" src="../assets/logo.png"> |
|||
<h2>Vítejte na naších stránkách</h2> |
|||
<router-link to="/products" class="btn btn-primary btn-lg"> ODKAZ NA PRODUKTY</router-link> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
|
|||
export default { |
|||
name: 'HomeView', |
|||
} |
|||
</script> |
@ -0,0 +1,41 @@ |
|||
<template> |
|||
<div v-if="product"> |
|||
<h1> {{ product.title }}</h1> |
|||
</div> |
|||
</template> |
|||
|
|||
|
|||
<script> |
|||
import axios from 'axios'; |
|||
|
|||
export default { |
|||
name: "ProductDetailView", |
|||
props: ["id"], |
|||
data() { |
|||
return { |
|||
product: null, |
|||
loading: true, |
|||
error: null, |
|||
} |
|||
}, |
|||
methods: { |
|||
async fetchProductDetail() { |
|||
try{ |
|||
const response = await axios.get(`https://dummyjson.com/products/${this.id}`) |
|||
this.product = response.data; |
|||
} catch (err) { |
|||
console.error ("Chyba při načítání:", err); |
|||
this.error = err |
|||
} finally { |
|||
this.loading = false; |
|||
} |
|||
} |
|||
}, |
|||
async mounted() { |
|||
await this.fetchProductDetail(); |
|||
}, |
|||
watch: { |
|||
id: "fetchProductDetail" // Pokud se změní prop 'id', zavolá se znovu metoda fetchProductDetail |
|||
} |
|||
} |
|||
</script> |
@ -0,0 +1,58 @@ |
|||
<template> |
|||
<div class="about"> |
|||
<h1>PRODUKTY</h1> |
|||
|
|||
<div v-if="loading"> |
|||
<h1>Načítám data</h1> |
|||
</div> |
|||
|
|||
<div v-if="error"> |
|||
Nastala chyba: {{ error.message }} |
|||
</div> |
|||
|
|||
<div v-for="product in products" :key="product.id"> |
|||
<router-link :to="'/products/' + product.id" |
|||
class="btn btn-lg btn-secondary my-1"> |
|||
{{ product.title }} |
|||
</router-link> |
|||
</div> |
|||
|
|||
<div v-if="!loading && !error && products.length === 0"> |
|||
Nebyly nalezeny žádné Produkty |
|||
</div> |
|||
|
|||
|
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import axios from 'axios'; |
|||
|
|||
export default{ |
|||
name: "ProductsView", |
|||
data() { |
|||
return { |
|||
products: [], |
|||
error: null, |
|||
loading: true |
|||
} |
|||
}, |
|||
methods: { |
|||
async fetchProducts() { |
|||
try{ |
|||
const response = await axios.get('https://dummyjson.com/products?limit=12') |
|||
this.products = response.data.products; |
|||
} catch (err) { |
|||
console.error ("Chyba při načítání:", err); |
|||
this.error = err |
|||
} finally { |
|||
this.loading = false; |
|||
} |
|||
} |
|||
}, |
|||
async mounted() { |
|||
await this.fetchProducts(); |
|||
} |
|||
} |
|||
|
|||
</script> |
@ -0,0 +1,4 @@ |
|||
const { defineConfig } = require('@vue/cli-service') |
|||
module.exports = defineConfig({ |
|||
transpileDependencies: true |
|||
}) |
@ -0,0 +1,4 @@ |
|||
> 1% |
|||
last 2 versions |
|||
not dead |
|||
not ie 11 |
@ -0,0 +1,17 @@ |
|||
module.exports = { |
|||
root: true, |
|||
env: { |
|||
node: true |
|||
}, |
|||
'extends': [ |
|||
'plugin:vue/vue3-essential', |
|||
'eslint:recommended' |
|||
], |
|||
parserOptions: { |
|||
parser: '@babel/eslint-parser' |
|||
}, |
|||
rules: { |
|||
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', |
|||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
.DS_Store |
|||
node_modules |
|||
/dist |
|||
|
|||
|
|||
# local env files |
|||
.env.local |
|||
.env.*.local |
|||
|
|||
# Log files |
|||
npm-debug.log* |
|||
yarn-debug.log* |
|||
yarn-error.log* |
|||
pnpm-debug.log* |
|||
|
|||
# Editor directories and files |
|||
.idea |
|||
.vscode |
|||
*.suo |
|||
*.ntvs* |
|||
*.njsproj |
|||
*.sln |
|||
*.sw? |
@ -0,0 +1,24 @@ |
|||
# routerapi |
|||
|
|||
## Project setup |
|||
``` |
|||
npm install |
|||
``` |
|||
|
|||
### Compiles and hot-reloads for development |
|||
``` |
|||
npm run serve |
|||
``` |
|||
|
|||
### Compiles and minifies for production |
|||
``` |
|||
npm run build |
|||
``` |
|||
|
|||
### Lints and fixes files |
|||
``` |
|||
npm run lint |
|||
``` |
|||
|
|||
### Customize configuration |
|||
See [Configuration Reference](https://cli.vuejs.org/config/). |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
presets: [ |
|||
'@vue/cli-plugin-babel/preset' |
|||
] |
|||
} |
@ -0,0 +1,19 @@ |
|||
{ |
|||
"compilerOptions": { |
|||
"target": "es5", |
|||
"module": "esnext", |
|||
"baseUrl": "./", |
|||
"moduleResolution": "node", |
|||
"paths": { |
|||
"@/*": [ |
|||
"src/*" |
|||
] |
|||
}, |
|||
"lib": [ |
|||
"esnext", |
|||
"dom", |
|||
"dom.iterable", |
|||
"scripthost" |
|||
] |
|||
} |
|||
} |
File diff suppressed because it is too large
@ -0,0 +1,27 @@ |
|||
{ |
|||
"name": "routerapi", |
|||
"version": "0.1.0", |
|||
"private": true, |
|||
"scripts": { |
|||
"serve": "vue-cli-service serve", |
|||
"build": "vue-cli-service build", |
|||
"lint": "vue-cli-service lint" |
|||
}, |
|||
"dependencies": { |
|||
"axios": "^1.9.0", |
|||
"bootstrap": "^5.3.6", |
|||
"core-js": "^3.8.3", |
|||
"vue": "^3.2.13", |
|||
"vue-router": "^4.0.3" |
|||
}, |
|||
"devDependencies": { |
|||
"@babel/core": "^7.12.16", |
|||
"@babel/eslint-parser": "^7.12.16", |
|||
"@vue/cli-plugin-babel": "~5.0.0", |
|||
"@vue/cli-plugin-eslint": "~5.0.0", |
|||
"@vue/cli-plugin-router": "~5.0.0", |
|||
"@vue/cli-service": "~5.0.0", |
|||
"eslint": "^7.32.0", |
|||
"eslint-plugin-vue": "^8.0.3" |
|||
} |
|||
} |
After Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,17 @@ |
|||
<!DOCTYPE html> |
|||
<html lang=""> |
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> |
|||
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> |
|||
<title><%= htmlWebpackPlugin.options.title %></title> |
|||
</head> |
|||
<body> |
|||
<noscript> |
|||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> |
|||
</noscript> |
|||
<div id="app"></div> |
|||
<!-- built files will be auto injected --> |
|||
</body> |
|||
</html> |
@ -0,0 +1,64 @@ |
|||
<template> |
|||
<div id="app"> |
|||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> |
|||
<div class="container"> |
|||
<router-link class="navbar-brand" to="/">Produkty API</router-link> |
|||
<button |
|||
class="navbar-toggler" |
|||
type="button" |
|||
data-bs-toggle="collapse" |
|||
data-bs-target="#navbarNav" |
|||
aria-controls="navbarNav" |
|||
aria-expanded="false" |
|||
aria-label="Toggle navigation" |
|||
> |
|||
<span class="navbar-toggler-icon"></span> |
|||
</button> |
|||
<div class="collapse navbar-collapse" id="navbarNav"> |
|||
<ul class="navbar-nav ms-auto"> |
|||
<li class="nav-item"> |
|||
<router-link class="nav-link" active-class="active" to="/">Domů</router-link> |
|||
</li> |
|||
<li class="nav-item"> |
|||
<router-link class="nav-link" active-class="active" to="/products">Produkty</router-link> |
|||
</li> |
|||
</ul> |
|||
</div> |
|||
</div> |
|||
</nav> |
|||
|
|||
<div class="container mt-4"> |
|||
<router-view /> |
|||
</div> |
|||
|
|||
<footer class="text-center text-muted py-3 mt-5 bg-light"> |
|||
Ukázka Vue Router & Axios © {{ new Date().getFullYear() }} |
|||
</footer> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
export default { |
|||
name: 'App', |
|||
}; |
|||
</script> |
|||
|
|||
<style> |
|||
/* Globální styly pro aplikaci */ |
|||
body { |
|||
font-family: 'Inter', sans-serif; /* Můžeš si zvolit jiný font */ |
|||
background-color: #f8f9fa; /* Světlé pozadí */ |
|||
} |
|||
|
|||
.navbar-brand { |
|||
font-weight: bold; |
|||
} |
|||
|
|||
/* active-class="active" z router-link přidá třídu .active, kterou můžeme nastylovat */ |
|||
.nav-link.active { |
|||
font-weight: bold; |
|||
/* Můžeš přidat další styly pro aktivní odkaz */ |
|||
} |
|||
|
|||
/* Můžeš přidat další vlastní styly, pokud Bootstrap nestačí */ |
|||
</style> |
After Width: | Height: | Size: 6.7 KiB |
@ -0,0 +1,59 @@ |
|||
<template> |
|||
<div class="hello"> |
|||
<h1>{{ msg }}</h1> |
|||
<p> |
|||
For a guide and recipes on how to configure / customize this project,<br> |
|||
check out the |
|||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>. |
|||
</p> |
|||
<h3>Installed CLI Plugins</h3> |
|||
<ul> |
|||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li> |
|||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router" target="_blank" rel="noopener">router</a></li> |
|||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li> |
|||
</ul> |
|||
<h3>Essential Links</h3> |
|||
<ul> |
|||
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li> |
|||
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li> |
|||
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li> |
|||
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li> |
|||
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li> |
|||
</ul> |
|||
<h3>Ecosystem</h3> |
|||
<ul> |
|||
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li> |
|||
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li> |
|||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li> |
|||
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li> |
|||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li> |
|||
</ul> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
export default { |
|||
name: 'HelloWorld', |
|||
props: { |
|||
msg: String |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<!-- Add "scoped" attribute to limit CSS to this component only --> |
|||
<style scoped> |
|||
h3 { |
|||
margin: 40px 0 0; |
|||
} |
|||
ul { |
|||
list-style-type: none; |
|||
padding: 0; |
|||
} |
|||
li { |
|||
display: inline-block; |
|||
margin: 0 10px; |
|||
} |
|||
a { |
|||
color: #42b983; |
|||
} |
|||
</style> |
@ -0,0 +1,5 @@ |
|||
import { createApp } from 'vue' |
|||
import App from './App.vue' |
|||
import router from './router' |
|||
import 'bootstrap/dist/css/bootstrap.min.css'; |
|||
createApp(App).use(router).mount('#app') |
@ -0,0 +1,30 @@ |
|||
import { createRouter, createWebHistory } from 'vue-router' |
|||
import HomePage from '../views/HomePage.vue'; |
|||
import ProductsPage from '../views/ProductsPage.vue'; |
|||
import ProductDetailPage from '../views/ProductDetailPage.vue'; |
|||
|
|||
const routes = [ |
|||
{ |
|||
path: '/', // Kořenová cesta
|
|||
name: 'Home', |
|||
component: HomePage, |
|||
}, |
|||
{ |
|||
path: '/products', // Cesta pro seznam produktů
|
|||
name: 'Products', |
|||
component: ProductsPage, |
|||
}, |
|||
{ |
|||
path: '/product/:id', // Cesta pro detail produktu, :id je dynamický parametr
|
|||
name: 'ProductDetail', |
|||
component: ProductDetailPage, |
|||
props: true, // Umožní předat :id jako prop komponentě ProductDetailPage
|
|||
}, |
|||
]; |
|||
|
|||
const router = createRouter({ |
|||
history: createWebHistory(process.env.BASE_URL), |
|||
routes |
|||
}) |
|||
|
|||
export default router |
@ -0,0 +1,43 @@ |
|||
<template> |
|||
<div class="p-5 mb-4 bg-light rounded-3 shadow-sm"> |
|||
<div class="container-fluid py-5"> |
|||
<h1 class="display-5 fw-bold">Vítejte v aplikaci Produkty!</h1> |
|||
<p class="col-md-8 fs-4"> |
|||
Toto je jednoduchá ukázková aplikace postavená na Vue.js 3, která demonstruje |
|||
použití Vue Routeru pro navigaci mezi stránkami a Axiosu pro načítání |
|||
dat z externího API (dummyjson.com). |
|||
</p> |
|||
<router-link class="btn btn-primary btn-lg" to="/products"> |
|||
Zobrazit produkty |
|||
</router-link> |
|||
</div> |
|||
</div> |
|||
|
|||
<div class="row align-items-md-stretch"> |
|||
<div class="col-md-6 mb-3"> |
|||
<div class="h-100 p-5 text-white bg-dark rounded-3 shadow"> |
|||
<h2>Vue Router</h2> |
|||
<p>Procházejte mezi stránkami "Domů", "Produkty" a detailem jednotlivých produktů pomocí navigační lišty výše. Vue Router se stará o plynulé přechody bez nutnosti znovunačítání celé stránky.</p> |
|||
</div> |
|||
</div> |
|||
<div class="col-md-6 mb-3"> |
|||
<div class="h-100 p-5 bg-body-secondary border rounded-3 shadow"> |
|||
<h2>Axios & API</h2> |
|||
<p>Na stránce "Produkty" uvidíte seznam produktů načtených asynchronně pomocí knihovny Axios z veřejného API. Kliknutím na produkt zobrazíte jeho detailní informace, které se také načítají dynamicky.</p> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
export default { |
|||
name: 'HomePage', |
|||
}; |
|||
</script> |
|||
|
|||
<style scoped> |
|||
/* Styly specifické pouze pro tuto komponentu */ |
|||
.display-5 { |
|||
color: #333; |
|||
} |
|||
</style> |
@ -0,0 +1,129 @@ |
|||
<template> |
|||
<div> |
|||
<router-link to="/products" class="btn btn-outline-secondary mb-4"> |
|||
« Zpět na seznam produktů |
|||
</router-link> |
|||
|
|||
<div v-if="error" class="alert alert-danger" role="alert"> |
|||
Nastala chyba při načítání detailu produktu: {{ error.message }} |
|||
</div> |
|||
|
|||
<div v-if="loading" class="d-flex justify-content-center my-5"> |
|||
<div class="spinner-border text-primary" role="status"> |
|||
<span class="visually-hidden">Načítám detail produktu...</span> |
|||
</div> |
|||
<p class="ms-3">Načítám detail produktu...</p> |
|||
</div> |
|||
|
|||
<div v-if="product && !loading && !error" class="card shadow-lg"> |
|||
<div class="row g-0"> |
|||
<div class="col-md-5"> |
|||
<img |
|||
:src="product.thumbnail" |
|||
class="img-fluid rounded-start w-100" |
|||
:alt="product.title" |
|||
style="max-height: 400px; object-fit: cover;" |
|||
@error="handleImageError" |
|||
/> |
|||
<div v-if="product.images && product.images.length > 1" id="productImagesCarousel" class="carousel slide carousel-fade p-3 bg-light" data-bs-ride="carousel"> |
|||
<div class="carousel-inner"> |
|||
<div v-for="(image, index) in product.images" :key="index" :class="['carousel-item', { active: index === 0 }]"> |
|||
<img :src="image" class="d-block w-100" :alt="`Obrázek produktu ${index + 1}`" style="height: 150px; object-fit: contain;"> |
|||
</div> |
|||
</div> |
|||
<button class="carousel-control-prev" type="button" data-bs-target="#productImagesCarousel" data-bs-slide="prev"> |
|||
<span class="carousel-control-prev-icon" aria-hidden="true"></span> |
|||
<span class="visually-hidden">Předchozí</span> |
|||
</button> |
|||
<button class="carousel-control-next" type="button" data-bs-target="#productImagesCarousel" data-bs-slide="next"> |
|||
<span class="carousel-control-next-icon" aria-hidden="true"></span> |
|||
<span class="visually-hidden">Další</span> |
|||
</button> |
|||
</div> |
|||
</div> |
|||
<div class="col-md-7"> |
|||
<div class="card-body p-4"> |
|||
<h1 class="card-title display-6 mb-3">{{ product.title }}</h1> |
|||
<p class="card-text text-muted mb-2">Kategorie: <span class="badge bg-info text-dark">{{ product.category }}</span></p> |
|||
<p class="card-text text-muted mb-2">Značka: {{ product.brand }}</p> |
|||
<p class="card-text fs-5 mb-3">{{ product.description }}</p> |
|||
<hr> |
|||
<div class="d-flex justify-content-between align-items-center mb-3"> |
|||
<p class="card-text fs-2 fw-bold text-primary mb-0">{{ product.price }}$</p> |
|||
<p v-if="product.discountPercentage > 0" class="text-danger mb-0"> |
|||
Sleva: {{ product.discountPercentage }}% |
|||
</p> |
|||
</div> |
|||
<p class="card-text"><small class="text-muted">Hodnocení: {{ product.rating }}/5</small></p> |
|||
<p class="card-text"><small class="text-muted">Skladem: {{ product.stock }} kusů</small></p> |
|||
<button class="btn btn-success btn-lg w-100 mt-3">Přidat do košíku (ukázka)</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import axios from 'axios'; |
|||
|
|||
export default { |
|||
name: 'ProductDetailPage', |
|||
props: ['id'], // Přijímá 'id' jako prop z routeru |
|||
data() { |
|||
return { |
|||
product: null, |
|||
loading: true, |
|||
error: null, |
|||
}; |
|||
}, |
|||
async mounted() { |
|||
await this.fetchProductDetail(); |
|||
}, |
|||
methods: { |
|||
async fetchProductDetail() { |
|||
this.loading = true; |
|||
this.error = null; |
|||
try { |
|||
// Použití ID z prop pro sestavení URL |
|||
const response = await axios.get(`https://dummyjson.com/products/${this.id}`); |
|||
this.product = response.data; |
|||
} catch (err) { |
|||
console.error('Chyba při načítání detailu produktu:', err); |
|||
this.error = err; |
|||
} finally { |
|||
this.loading = false; |
|||
} |
|||
}, |
|||
handleImageError(event) { |
|||
event.target.src = 'https://placehold.co/400x400/e9ecef/6c757d?text=Obrázek+není+k+dispozici'; |
|||
} |
|||
}, |
|||
// Sledování změn ID v URL (pokud by se navigovalo mezi detaily různých produktů) |
|||
watch: { |
|||
id: 'fetchProductDetail' // Pokud se změní prop 'id', zavolá se znovu metoda fetchProductDetail |
|||
} |
|||
}; |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.card { |
|||
border: none; /* Odstranění výchozího ohraničení karty pro čistší vzhled se stínem */ |
|||
} |
|||
.img-fluid { |
|||
border-top-left-radius: var(--bs-card-inner-border-radius); |
|||
border-bottom-left-radius: var(--bs-card-inner-border-radius); /* Pro zaoblení na mobilu */ |
|||
} |
|||
@media (max-width: 767.98px) { /* Styly pro menší obrazovky */ |
|||
.img-fluid { |
|||
border-bottom-left-radius: 0; |
|||
border-top-right-radius: var(--bs-card-inner-border-radius); |
|||
} |
|||
} |
|||
.carousel-control-prev-icon, |
|||
.carousel-control-next-icon { |
|||
background-color: rgba(0, 0, 0, 0.3); |
|||
border-radius: 50%; |
|||
} |
|||
</style> |
|||
|
@ -0,0 +1,103 @@ |
|||
<template> |
|||
<div> |
|||
<h1 class="mb-4">Seznam produktů</h1> |
|||
|
|||
<div v-if="error" class="alert alert-danger" role="alert"> |
|||
Nastala chyba při načítání produktů: {{ error.message }} |
|||
</div> |
|||
|
|||
<div v-if="loading" class="d-flex justify-content-center my-5"> |
|||
<div class="spinner-border text-primary" role="status"> |
|||
<span class="visually-hidden">Načítám produkty...</span> |
|||
</div> |
|||
<p class="ms-3">Načítám produkty...</p> |
|||
</div> |
|||
|
|||
<div v-if="!loading && !error && products.length > 0" class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-4"> |
|||
<div v-for="product in products" :key="product.id" class="col"> |
|||
<div class="card h-100 shadow-sm"> |
|||
<img |
|||
:src="product.thumbnail" |
|||
class="card-img-top" |
|||
:alt="product.title" |
|||
style="height: 200px; object-fit: cover;" |
|||
@error="handleImageError" |
|||
/> |
|||
<div class="card-body d-flex flex-column"> |
|||
<h5 class="card-title">{{ product.title }}</h5> |
|||
<p class="card-text text-muted small">{{ product.category }}</p> |
|||
<p class="card-text flex-grow-1">{{ truncateDescription(product.description, 80) }}</p> |
|||
<div class="d-flex justify-content-between align-items-center mt-auto"> |
|||
<span class="fw-bold fs-5 text-primary">{{ product.price }}$</span> |
|||
<router-link :to="'/product/' + product.id" class="btn btn-outline-primary btn-sm"> |
|||
Detail |
|||
</router-link> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
<div v-if="!loading && !error && products.length === 0" class="alert alert-info" role="alert"> |
|||
Nebyly nalezeny žádné produkty. |
|||
</div> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import axios from 'axios'; // Import Axiosu |
|||
|
|||
export default { |
|||
name: 'ProductsPage', |
|||
data() { |
|||
return { |
|||
products: [], // Pole pro uložení načtených produktů |
|||
loading: true, // Indikátor načítání |
|||
error: null, // Objekt pro uložení případné chyby |
|||
}; |
|||
}, |
|||
// Metoda mounted se zavolá, když je komponenta připojena do DOMu |
|||
async mounted() { |
|||
await this.fetchProducts(); |
|||
}, |
|||
methods: { |
|||
async fetchProducts() { |
|||
this.loading = true; |
|||
this.error = null; |
|||
try { |
|||
// Použití Axiosu pro GET požadavek na API |
|||
const response = await axios.get('https://dummyjson.com/products?limit=12'); // Omezíme na 12 produktů pro přehlednost |
|||
this.products = response.data.products; // Uložení dat z odpovědi |
|||
} catch (err) { |
|||
console.error('Chyba při načítání produktů:', err); |
|||
this.error = err; // Uložení chyby pro zobrazení uživateli |
|||
} finally { |
|||
this.loading = false; // Ukončení načítání (ať už úspěšně nebo neúspěšně) |
|||
} |
|||
}, |
|||
truncateDescription(text, length) { |
|||
// Jednoduchá funkce pro zkrácení popisu |
|||
if (text.length <= length) { |
|||
return text; |
|||
} |
|||
return text.substring(0, length) + '...'; |
|||
}, |
|||
handleImageError(event) { |
|||
// Náhradní obrázek, pokud se originální nepodaří načíst |
|||
event.target.src = 'https://placehold.co/300x200/e9ecef/6c757d?text=Obrázek+není+k+dispozici'; |
|||
} |
|||
}, |
|||
}; |
|||
</script> |
|||
|
|||
<style scoped> |
|||
.card-img-top { |
|||
border-bottom: 1px solid #eee; |
|||
} |
|||
.card-title { |
|||
min-height: 48px; /* Zajistí přibližně stejnou výšku pro titulky */ |
|||
} |
|||
.card-text { |
|||
font-size: 0.9rem; |
|||
} |
|||
</style> |
@ -0,0 +1,4 @@ |
|||
const { defineConfig } = require('@vue/cli-service') |
|||
module.exports = defineConfig({ |
|||
transpileDependencies: true |
|||
}) |
Loading…
Reference in new issue